blob: 2e7342d5880776cdd755c216e526e9796afa7e05 [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"
Daniel Dunbar3483aca2010-08-11 05:24:50 +000012#include "ARMSubtarget.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000013#include "llvm/MC/MCParser/MCAsmLexer.h"
14#include "llvm/MC/MCParser/MCAsmParser.h"
15#include "llvm/MC/MCParser/MCParsedAsmOperand.h"
Jim Grosbach642fc9c2010-11-05 22:33:53 +000016#include "llvm/MC/MCContext.h"
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000017#include "llvm/MC/MCStreamer.h"
18#include "llvm/MC/MCExpr.h"
19#include "llvm/MC/MCInst.h"
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000020#include "llvm/Target/TargetRegistry.h"
21#include "llvm/Target/TargetAsmParser.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000022#include "llvm/Support/SourceMgr.h"
Daniel Dunbarfa315de2010-08-11 06:37:12 +000023#include "llvm/Support/raw_ostream.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000024#include "llvm/ADT/SmallVector.h"
Daniel Dunbar345a9a62010-08-11 06:37:20 +000025#include "llvm/ADT/StringSwitch.h"
Chris Lattnerc6ef2772010-01-22 01:44:57 +000026#include "llvm/ADT/Twine.h"
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000027using namespace llvm;
28
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000029// The shift types for register controlled shifts in arm memory addressing
30enum ShiftType {
31 Lsl,
32 Lsr,
33 Asr,
34 Ror,
35 Rrx
36};
37
Chris Lattner3a697562010-10-28 17:20:03 +000038namespace {
Bill Wendling146018f2010-11-06 21:42:12 +000039
40class ARMOperand;
Jim Grosbach16c74252010-10-29 14:46:02 +000041
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000042class ARMAsmParser : public TargetAsmParser {
43 MCAsmParser &Parser;
Daniel Dunbard73ada72010-07-19 00:33:49 +000044 TargetMachine &TM;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000045
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000046 MCAsmParser &getParser() const { return Parser; }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000047 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
48
49 void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000050 bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
51
Chris Lattnere5658fa2010-10-30 04:09:10 +000052 int TryParseRegister();
Bill Wendling50d0f582010-11-18 23:43:05 +000053 bool TryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &);
54 bool ParseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &);
55 bool ParseMemory(SmallVectorImpl<MCParsedAsmOperand*> &);
56 bool ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000057
Kevin Enderby9c41fa82009-10-30 22:55:57 +000058 bool ParseMemoryOffsetReg(bool &Negative,
59 bool &OffsetRegShifted,
60 enum ShiftType &ShiftType,
61 const MCExpr *&ShiftAmount,
62 const MCExpr *&Offset,
63 bool &OffsetIsReg,
Sean Callanan76264762010-04-02 22:27:05 +000064 int &OffsetRegNum,
65 SMLoc &E);
Sean Callanan76264762010-04-02 22:27:05 +000066 bool ParseShift(enum ShiftType &St, const MCExpr *&ShiftAmount, SMLoc &E);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000067 bool ParseDirectiveWord(unsigned Size, SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000068 bool ParseDirectiveThumb(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000069 bool ParseDirectiveThumbFunc(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000070 bool ParseDirectiveCode(SMLoc L);
Kevin Enderby515d5092009-10-15 20:48:48 +000071 bool ParseDirectiveSyntax(SMLoc L);
72
Chris Lattner7036f8b2010-09-29 01:42:58 +000073 bool MatchAndEmitInstruction(SMLoc IDLoc,
Chris Lattner7c51a312010-09-29 01:50:45 +000074 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
Chris Lattnerfa42fad2010-10-28 21:28:01 +000075 MCStreamer &Out);
Jim Grosbach16c74252010-10-29 14:46:02 +000076
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000077 /// @name Auto-generated Match Functions
78 /// {
Daniel Dunbar3483aca2010-08-11 05:24:50 +000079
Chris Lattner0692ee62010-09-06 19:11:01 +000080#define GET_ASSEMBLER_HEADER
81#include "ARMGenAsmMatcher.inc"
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000082
Kevin Enderbya7ba3a82009-10-06 22:26:42 +000083 /// }
84
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000085public:
Daniel Dunbard73ada72010-07-19 00:33:49 +000086 ARMAsmParser(const Target &T, MCAsmParser &_Parser, TargetMachine &_TM)
Jim Grosbach833c93c2010-11-01 16:59:54 +000087 : TargetAsmParser(T), Parser(_Parser), TM(_TM) {
88 // Initialize the set of available features.
89 setAvailableFeatures(ComputeAvailableFeatures(
90 &TM.getSubtarget<ARMSubtarget>()));
91 }
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000092
Benjamin Kramer38e59892010-07-14 22:38:02 +000093 virtual bool ParseInstruction(StringRef Name, SMLoc NameLoc,
Chris Lattner98986712010-01-14 22:21:20 +000094 SmallVectorImpl<MCParsedAsmOperand*> &Operands);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +000095 virtual bool ParseDirective(AsmToken DirectiveID);
96};
Jim Grosbach16c74252010-10-29 14:46:02 +000097} // end anonymous namespace
98
Chris Lattner3a697562010-10-28 17:20:03 +000099namespace {
100
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000101/// ARMOperand - Instances of this class represent a parsed ARM machine
102/// instruction.
Bill Wendling146018f2010-11-06 21:42:12 +0000103class ARMOperand : public MCParsedAsmOperand {
Sean Callanan76264762010-04-02 22:27:05 +0000104 enum KindTy {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000105 CondCode,
Kevin Enderbycfe07242009-10-13 22:19:02 +0000106 Immediate,
Daniel Dunbar8462b302010-08-11 06:36:53 +0000107 Memory,
108 Register,
Bill Wendling8d5acb72010-11-06 19:56:04 +0000109 RegisterList,
Bill Wendling0f630752010-11-17 04:32:08 +0000110 DPRRegisterList,
111 SPRRegisterList,
Daniel Dunbar8462b302010-08-11 06:36:53 +0000112 Token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000113 } Kind;
114
Sean Callanan76264762010-04-02 22:27:05 +0000115 SMLoc StartLoc, EndLoc;
Bill Wendling24d22d22010-11-18 21:50:54 +0000116 SmallVector<unsigned, 8> Registers;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000117
118 union {
119 struct {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000120 ARMCC::CondCodes Val;
121 } CC;
122
123 struct {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000124 const char *Data;
125 unsigned Length;
126 } Tok;
127
128 struct {
129 unsigned RegNum;
130 } Reg;
131
Bill Wendling8155e5b2010-11-06 22:19:43 +0000132 struct {
Kevin Enderbycfe07242009-10-13 22:19:02 +0000133 const MCExpr *Val;
134 } Imm;
Jim Grosbach16c74252010-10-29 14:46:02 +0000135
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000136 // This is for all forms of ARM address expressions
137 struct {
138 unsigned BaseRegNum;
Bill Wendling146018f2010-11-06 21:42:12 +0000139 unsigned OffsetRegNum; // used when OffsetIsReg is true
140 const MCExpr *Offset; // used when OffsetIsReg is false
141 const MCExpr *ShiftAmount; // used when OffsetRegShifted is true
142 enum ShiftType ShiftType; // used when OffsetRegShifted is true
143 unsigned OffsetRegShifted : 1; // only used when OffsetIsReg is true
Bill Wendling50d0f582010-11-18 23:43:05 +0000144 unsigned Preindexed : 1;
145 unsigned Postindexed : 1;
146 unsigned OffsetIsReg : 1;
147 unsigned Negative : 1; // only used when OffsetIsReg is true
148 unsigned Writeback : 1;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000149 } Mem;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000150 };
Jim Grosbach16c74252010-10-29 14:46:02 +0000151
Bill Wendling146018f2010-11-06 21:42:12 +0000152 ARMOperand(KindTy K) : MCParsedAsmOperand(), Kind(K) {}
153public:
Sean Callanan76264762010-04-02 22:27:05 +0000154 ARMOperand(const ARMOperand &o) : MCParsedAsmOperand() {
155 Kind = o.Kind;
156 StartLoc = o.StartLoc;
157 EndLoc = o.EndLoc;
158 switch (Kind) {
Daniel Dunbar8462b302010-08-11 06:36:53 +0000159 case CondCode:
160 CC = o.CC;
161 break;
Sean Callanan76264762010-04-02 22:27:05 +0000162 case Token:
Daniel Dunbar8462b302010-08-11 06:36:53 +0000163 Tok = o.Tok;
Sean Callanan76264762010-04-02 22:27:05 +0000164 break;
165 case Register:
166 Reg = o.Reg;
167 break;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000168 case RegisterList:
Bill Wendling0f630752010-11-17 04:32:08 +0000169 case DPRRegisterList:
170 case SPRRegisterList:
Bill Wendling24d22d22010-11-18 21:50:54 +0000171 Registers = o.Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000172 break;
Sean Callanan76264762010-04-02 22:27:05 +0000173 case Immediate:
174 Imm = o.Imm;
175 break;
176 case Memory:
177 Mem = o.Mem;
178 break;
179 }
180 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000181
Sean Callanan76264762010-04-02 22:27:05 +0000182 /// getStartLoc - Get the location of the first token of this operand.
183 SMLoc getStartLoc() const { return StartLoc; }
184 /// getEndLoc - Get the location of the last token of this operand.
185 SMLoc getEndLoc() const { return EndLoc; }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000186
Daniel Dunbar8462b302010-08-11 06:36:53 +0000187 ARMCC::CondCodes getCondCode() const {
188 assert(Kind == CondCode && "Invalid access!");
189 return CC.Val;
190 }
191
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000192 StringRef getToken() const {
193 assert(Kind == Token && "Invalid access!");
194 return StringRef(Tok.Data, Tok.Length);
195 }
196
197 unsigned getReg() const {
Bill Wendling7729e062010-11-09 22:44:22 +0000198 assert(Kind == Register && "Invalid access!");
199 return Reg.RegNum;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000200 }
201
Bill Wendling5fa22a12010-11-09 23:28:44 +0000202 const SmallVectorImpl<unsigned> &getRegList() const {
Bill Wendling0f630752010-11-17 04:32:08 +0000203 assert((Kind == RegisterList || Kind == DPRRegisterList ||
204 Kind == SPRRegisterList) && "Invalid access!");
Bill Wendling24d22d22010-11-18 21:50:54 +0000205 return Registers;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000206 }
207
Kevin Enderbycfe07242009-10-13 22:19:02 +0000208 const MCExpr *getImm() const {
209 assert(Kind == Immediate && "Invalid access!");
210 return Imm.Val;
211 }
212
Daniel Dunbar8462b302010-08-11 06:36:53 +0000213 bool isCondCode() const { return Kind == CondCode; }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000214 bool isImm() const { return Kind == Immediate; }
Bill Wendlingb32e7842010-11-08 00:32:40 +0000215 bool isReg() const { return Kind == Register; }
Bill Wendling8d5acb72010-11-06 19:56:04 +0000216 bool isRegList() const { return Kind == RegisterList; }
Bill Wendling0f630752010-11-17 04:32:08 +0000217 bool isDPRRegList() const { return Kind == DPRRegisterList; }
218 bool isSPRRegList() const { return Kind == SPRRegisterList; }
Chris Lattner14b93852010-10-29 00:27:31 +0000219 bool isToken() const { return Kind == Token; }
220 bool isMemory() const { return Kind == Memory; }
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000221 bool isMemMode5() const {
222 if (!isMemory() || Mem.OffsetIsReg || Mem.OffsetRegShifted ||
223 Mem.Writeback || Mem.Negative)
224 return false;
225 // If there is an offset expression, make sure it's valid.
226 if (!Mem.Offset)
227 return true;
228 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.Offset);
229 if (!CE)
230 return false;
231 // The offset must be a multiple of 4 in the range 0-1020.
232 int64_t Value = CE->getValue();
233 return ((Value & 0x3) == 0 && Value <= 1020 && Value >= -1020);
234 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000235
236 void addExpr(MCInst &Inst, const MCExpr *Expr) const {
Chris Lattner14b93852010-10-29 00:27:31 +0000237 // Add as immediates when possible. Null MCExpr = 0.
238 if (Expr == 0)
239 Inst.addOperand(MCOperand::CreateImm(0));
240 else if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Expr))
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000241 Inst.addOperand(MCOperand::CreateImm(CE->getValue()));
242 else
243 Inst.addOperand(MCOperand::CreateExpr(Expr));
244 }
245
Daniel Dunbar8462b302010-08-11 06:36:53 +0000246 void addCondCodeOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000247 assert(N == 2 && "Invalid number of operands!");
Daniel Dunbar8462b302010-08-11 06:36:53 +0000248 Inst.addOperand(MCOperand::CreateImm(unsigned(getCondCode())));
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000249 // FIXME: What belongs here?
250 Inst.addOperand(MCOperand::CreateReg(0));
Daniel Dunbar8462b302010-08-11 06:36:53 +0000251 }
252
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000253 void addRegOperands(MCInst &Inst, unsigned N) const {
254 assert(N == 1 && "Invalid number of operands!");
255 Inst.addOperand(MCOperand::CreateReg(getReg()));
256 }
257
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000258 void addRegListOperands(MCInst &Inst, unsigned N) const {
Bill Wendling7729e062010-11-09 22:44:22 +0000259 assert(N == 1 && "Invalid number of operands!");
Bill Wendling5fa22a12010-11-09 23:28:44 +0000260 const SmallVectorImpl<unsigned> &RegList = getRegList();
261 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000262 I = RegList.begin(), E = RegList.end(); I != E; ++I)
263 Inst.addOperand(MCOperand::CreateReg(*I));
Bill Wendling87f4f9a2010-11-08 23:49:57 +0000264 }
265
Bill Wendling0f630752010-11-17 04:32:08 +0000266 void addDPRRegListOperands(MCInst &Inst, unsigned N) const {
267 addRegListOperands(Inst, N);
268 }
269
270 void addSPRRegListOperands(MCInst &Inst, unsigned N) const {
271 addRegListOperands(Inst, N);
272 }
273
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000274 void addImmOperands(MCInst &Inst, unsigned N) const {
275 assert(N == 1 && "Invalid number of operands!");
276 addExpr(Inst, getImm());
277 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000278
Chris Lattner14b93852010-10-29 00:27:31 +0000279 void addMemMode5Operands(MCInst &Inst, unsigned N) const {
280 assert(N == 2 && isMemMode5() && "Invalid number of operands!");
Jim Grosbach16c74252010-10-29 14:46:02 +0000281
Chris Lattner14b93852010-10-29 00:27:31 +0000282 Inst.addOperand(MCOperand::CreateReg(Mem.BaseRegNum));
Bill Wendlinga60f1572010-11-06 10:48:18 +0000283 assert(!Mem.OffsetIsReg && "Invalid mode 5 operand");
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000284
Jim Grosbach80eb2332010-10-29 17:41:25 +0000285 // FIXME: #-0 is encoded differently than #0. Does the parser preserve
286 // the difference?
287 if (Mem.Offset) {
288 const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(Mem.Offset);
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000289 assert(CE && "Non-constant mode 5 offset operand!");
290
Jim Grosbach80eb2332010-10-29 17:41:25 +0000291 // The MCInst offset operand doesn't include the low two bits (like
292 // the instruction encoding).
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000293 int64_t Offset = CE->getValue() / 4;
294 if (Offset >= 0)
295 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::add,
296 Offset)));
297 else
298 Inst.addOperand(MCOperand::CreateImm(ARM_AM::getAM5Opc(ARM_AM::sub,
299 -Offset)));
300 } else {
Jim Grosbach80eb2332010-10-29 17:41:25 +0000301 Inst.addOperand(MCOperand::CreateImm(0));
Bill Wendling92b5a2e2010-11-03 01:49:29 +0000302 }
Chris Lattner14b93852010-10-29 00:27:31 +0000303 }
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000304
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000305 virtual void dump(raw_ostream &OS) const;
Daniel Dunbarb3cb6962010-08-11 06:37:04 +0000306
Chris Lattner3a697562010-10-28 17:20:03 +0000307 static ARMOperand *CreateCondCode(ARMCC::CondCodes CC, SMLoc S) {
308 ARMOperand *Op = new ARMOperand(CondCode);
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000309 Op->CC.Val = CC;
310 Op->StartLoc = S;
311 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +0000312 return Op;
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000313 }
314
Chris Lattner3a697562010-10-28 17:20:03 +0000315 static ARMOperand *CreateToken(StringRef Str, SMLoc S) {
316 ARMOperand *Op = new ARMOperand(Token);
Sean Callanan76264762010-04-02 22:27:05 +0000317 Op->Tok.Data = Str.data();
318 Op->Tok.Length = Str.size();
319 Op->StartLoc = S;
320 Op->EndLoc = S;
Chris Lattner3a697562010-10-28 17:20:03 +0000321 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000322 }
323
Bill Wendling50d0f582010-11-18 23:43:05 +0000324 static ARMOperand *CreateReg(unsigned RegNum, SMLoc S, SMLoc E) {
Chris Lattner3a697562010-10-28 17:20:03 +0000325 ARMOperand *Op = new ARMOperand(Register);
Sean Callanan76264762010-04-02 22:27:05 +0000326 Op->Reg.RegNum = RegNum;
Sean Callanan76264762010-04-02 22:27:05 +0000327 Op->StartLoc = S;
328 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000329 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000330 }
331
Bill Wendling7729e062010-11-09 22:44:22 +0000332 static ARMOperand *
Bill Wendling5fa22a12010-11-09 23:28:44 +0000333 CreateRegList(const SmallVectorImpl<std::pair<unsigned, SMLoc> > &Regs,
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +0000334 SMLoc StartLoc, SMLoc EndLoc) {
Bill Wendling0f630752010-11-17 04:32:08 +0000335 KindTy Kind = RegisterList;
336
337 if (ARM::DPRRegClass.contains(Regs.front().first))
338 Kind = DPRRegisterList;
339 else if (ARM::SPRRegClass.contains(Regs.front().first))
340 Kind = SPRRegisterList;
341
342 ARMOperand *Op = new ARMOperand(Kind);
Bill Wendling5fa22a12010-11-09 23:28:44 +0000343 for (SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000344 I = Regs.begin(), E = Regs.end(); I != E; ++I)
Bill Wendling24d22d22010-11-18 21:50:54 +0000345 Op->Registers.push_back(I->first);
Bill Wendlingcb21d1c2010-11-19 00:38:19 +0000346 array_pod_sort(Op->Registers.begin(), Op->Registers.end());
Matt Beaumont-Gaycc8d10e2010-11-10 00:08:58 +0000347 Op->StartLoc = StartLoc;
348 Op->EndLoc = EndLoc;
Bill Wendling8d5acb72010-11-06 19:56:04 +0000349 return Op;
350 }
351
Chris Lattner3a697562010-10-28 17:20:03 +0000352 static ARMOperand *CreateImm(const MCExpr *Val, SMLoc S, SMLoc E) {
353 ARMOperand *Op = new ARMOperand(Immediate);
Sean Callanan76264762010-04-02 22:27:05 +0000354 Op->Imm.Val = Val;
Sean Callanan76264762010-04-02 22:27:05 +0000355 Op->StartLoc = S;
356 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000357 return Op;
Kevin Enderbycfe07242009-10-13 22:19:02 +0000358 }
359
Chris Lattner3a697562010-10-28 17:20:03 +0000360 static ARMOperand *CreateMem(unsigned BaseRegNum, bool OffsetIsReg,
361 const MCExpr *Offset, unsigned OffsetRegNum,
362 bool OffsetRegShifted, enum ShiftType ShiftType,
363 const MCExpr *ShiftAmount, bool Preindexed,
364 bool Postindexed, bool Negative, bool Writeback,
365 SMLoc S, SMLoc E) {
366 ARMOperand *Op = new ARMOperand(Memory);
Sean Callanan76264762010-04-02 22:27:05 +0000367 Op->Mem.BaseRegNum = BaseRegNum;
368 Op->Mem.OffsetIsReg = OffsetIsReg;
369 Op->Mem.Offset = Offset;
370 Op->Mem.OffsetRegNum = OffsetRegNum;
371 Op->Mem.OffsetRegShifted = OffsetRegShifted;
372 Op->Mem.ShiftType = ShiftType;
373 Op->Mem.ShiftAmount = ShiftAmount;
374 Op->Mem.Preindexed = Preindexed;
375 Op->Mem.Postindexed = Postindexed;
376 Op->Mem.Negative = Negative;
377 Op->Mem.Writeback = Writeback;
Jim Grosbach16c74252010-10-29 14:46:02 +0000378
Sean Callanan76264762010-04-02 22:27:05 +0000379 Op->StartLoc = S;
380 Op->EndLoc = E;
Chris Lattner3a697562010-10-28 17:20:03 +0000381 return Op;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000382 }
383};
384
385} // end anonymous namespace.
386
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000387void ARMOperand::dump(raw_ostream &OS) const {
388 switch (Kind) {
389 case CondCode:
390 OS << ARMCondCodeToString(getCondCode());
391 break;
392 case Immediate:
393 getImm()->print(OS);
394 break;
395 case Memory:
Bill Wendling50d0f582010-11-18 23:43:05 +0000396 OS << "<memory>";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000397 break;
398 case Register:
Bill Wendling50d0f582010-11-18 23:43:05 +0000399 OS << "<register " << getReg() << ">";
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000400 break;
Bill Wendling0f630752010-11-17 04:32:08 +0000401 case RegisterList:
402 case DPRRegisterList:
403 case SPRRegisterList: {
Bill Wendling8d5acb72010-11-06 19:56:04 +0000404 OS << "<register_list ";
Bill Wendling8d5acb72010-11-06 19:56:04 +0000405
Bill Wendling5fa22a12010-11-09 23:28:44 +0000406 const SmallVectorImpl<unsigned> &RegList = getRegList();
407 for (SmallVectorImpl<unsigned>::const_iterator
Bill Wendling7729e062010-11-09 22:44:22 +0000408 I = RegList.begin(), E = RegList.end(); I != E; ) {
409 OS << *I;
410 if (++I < E) OS << ", ";
Bill Wendling8d5acb72010-11-06 19:56:04 +0000411 }
412
413 OS << ">";
414 break;
415 }
Daniel Dunbarfa315de2010-08-11 06:37:12 +0000416 case Token:
417 OS << "'" << getToken() << "'";
418 break;
419 }
420}
Daniel Dunbar3483aca2010-08-11 05:24:50 +0000421
422/// @name Auto-generated Match Functions
423/// {
424
425static unsigned MatchRegisterName(StringRef Name);
426
427/// }
428
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000429/// Try to parse a register name. The token must be an Identifier when called,
Chris Lattnere5658fa2010-10-30 04:09:10 +0000430/// and if it is a register name the token is eaten and the register number is
431/// returned. Otherwise return -1.
432///
433int ARMAsmParser::TryParseRegister() {
434 const AsmToken &Tok = Parser.getTok();
435 assert(Tok.is(AsmToken::Identifier) && "Token is not an Identifier");
Jim Grosbachd4462a52010-11-01 16:44:21 +0000436
Chris Lattnere5658fa2010-10-30 04:09:10 +0000437 // FIXME: Validate register for the current architecture; we have to do
438 // validation later, so maybe there is no need for this here.
Bill Wendlingd68fd9c2010-11-06 10:45:34 +0000439 unsigned RegNum = MatchRegisterName(Tok.getString());
440 if (RegNum == 0)
Chris Lattnere5658fa2010-10-30 04:09:10 +0000441 return -1;
442 Parser.Lex(); // Eat identifier token.
443 return RegNum;
444}
Jim Grosbachd4462a52010-11-01 16:44:21 +0000445
446
Bill Wendling50d0f582010-11-18 23:43:05 +0000447/// Try to parse a register name. The token must be an Identifier when called.
448/// If it's a register, an AsmOperand is created. Another AsmOperand is created
449/// if there is a "writeback". 'true' if it's not a register.
Chris Lattner3a697562010-10-28 17:20:03 +0000450///
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000451/// TODO this is likely to change to allow different register types and or to
452/// parse for a specific register type.
Bill Wendling50d0f582010-11-18 23:43:05 +0000453bool ARMAsmParser::
454TryParseRegisterWithWriteBack(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Chris Lattnere5658fa2010-10-30 04:09:10 +0000455 SMLoc S = Parser.getTok().getLoc();
456 int RegNo = TryParseRegister();
Bill Wendlinge7176102010-11-06 22:36:58 +0000457 if (RegNo == -1)
Bill Wendling50d0f582010-11-18 23:43:05 +0000458 return true;
Jim Grosbachd4462a52010-11-01 16:44:21 +0000459
Bill Wendling50d0f582010-11-18 23:43:05 +0000460 Operands.push_back(ARMOperand::CreateReg(RegNo, S, Parser.getTok().getLoc()));
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000461
Chris Lattnere5658fa2010-10-30 04:09:10 +0000462 const AsmToken &ExclaimTok = Parser.getTok();
463 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +0000464 Operands.push_back(ARMOperand::CreateToken(ExclaimTok.getString(),
465 ExclaimTok.getLoc()));
Chris Lattnere5658fa2010-10-30 04:09:10 +0000466 Parser.Lex(); // Eat exclaim token
Kevin Enderby99e6d4e2009-10-07 18:01:35 +0000467 }
468
Bill Wendling50d0f582010-11-18 23:43:05 +0000469 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000470}
471
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000472/// Parse a register list, return it if successful else return null. The first
473/// token must be a '{' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +0000474bool ARMAsmParser::
475ParseRegisterList(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan18b83232010-01-19 21:44:56 +0000476 assert(Parser.getTok().is(AsmToken::LCurly) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +0000477 "Token is not a Left Curly Brace");
Bill Wendlinge7176102010-11-06 22:36:58 +0000478 SMLoc S = Parser.getTok().getLoc();
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000479
Bill Wendling7729e062010-11-09 22:44:22 +0000480 // Read the rest of the registers in the list.
481 unsigned PrevRegNum = 0;
Bill Wendling5fa22a12010-11-09 23:28:44 +0000482 SmallVector<std::pair<unsigned, SMLoc>, 32> Registers;
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000483
Bill Wendling7729e062010-11-09 22:44:22 +0000484 do {
Bill Wendlinge7176102010-11-06 22:36:58 +0000485 bool IsRange = Parser.getTok().is(AsmToken::Minus);
Bill Wendling7729e062010-11-09 22:44:22 +0000486 Parser.Lex(); // Eat non-identifier token.
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000487
Sean Callanan18b83232010-01-19 21:44:56 +0000488 const AsmToken &RegTok = Parser.getTok();
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000489 SMLoc RegLoc = RegTok.getLoc();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000490 if (RegTok.isNot(AsmToken::Identifier)) {
491 Error(RegLoc, "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000492 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000493 }
Bill Wendlinge7176102010-11-06 22:36:58 +0000494
Bill Wendling1d6a2652010-11-06 10:40:24 +0000495 int RegNum = TryParseRegister();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000496 if (RegNum == -1) {
497 Error(RegLoc, "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000498 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000499 }
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000500
Bill Wendlinge7176102010-11-06 22:36:58 +0000501 if (IsRange) {
502 int Reg = PrevRegNum;
503 do {
504 ++Reg;
505 Registers.push_back(std::make_pair(Reg, RegLoc));
506 } while (Reg != RegNum);
507 } else {
508 Registers.push_back(std::make_pair(RegNum, RegLoc));
509 }
510
511 PrevRegNum = RegNum;
Bill Wendling7729e062010-11-09 22:44:22 +0000512 } while (Parser.getTok().is(AsmToken::Comma) ||
513 Parser.getTok().is(AsmToken::Minus));
Bill Wendlinge7176102010-11-06 22:36:58 +0000514
515 // Process the right curly brace of the list.
Sean Callanan18b83232010-01-19 21:44:56 +0000516 const AsmToken &RCurlyTok = Parser.getTok();
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000517 if (RCurlyTok.isNot(AsmToken::RCurly)) {
518 Error(RCurlyTok.getLoc(), "'}' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000519 return true;
Chris Lattnerc0ddfaa2010-10-28 17:23:41 +0000520 }
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000521
Bill Wendlinge7176102010-11-06 22:36:58 +0000522 SMLoc E = RCurlyTok.getLoc();
523 Parser.Lex(); // Eat right curly brace token.
Jim Grosbach03f44a02010-11-29 23:18:01 +0000524
Bill Wendlinge7176102010-11-06 22:36:58 +0000525 // Verify the register list.
Bill Wendling5fa22a12010-11-09 23:28:44 +0000526 SmallVectorImpl<std::pair<unsigned, SMLoc> >::const_iterator
Bill Wendlinge7176102010-11-06 22:36:58 +0000527 RI = Registers.begin(), RE = Registers.end();
528
Bill Wendlinge7176102010-11-06 22:36:58 +0000529 DenseMap<unsigned, bool> RegMap;
530 RegMap[RI->first] = true;
531
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000532 unsigned HighRegNum = RI->first;
533 bool EmittedWarning = false;
534
Bill Wendlinge7176102010-11-06 22:36:58 +0000535 for (++RI; RI != RE; ++RI) {
Bill Wendling7729e062010-11-09 22:44:22 +0000536 const std::pair<unsigned, SMLoc> &RegInfo = *RI;
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000537 unsigned Reg = RegInfo.first;
Bill Wendlinge7176102010-11-06 22:36:58 +0000538
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000539 if (RegMap[Reg]) {
Bill Wendlinge7176102010-11-06 22:36:58 +0000540 Error(RegInfo.second, "register duplicated in register list");
Bill Wendling50d0f582010-11-18 23:43:05 +0000541 return true;
Bill Wendlinge7176102010-11-06 22:36:58 +0000542 }
543
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000544 if (!EmittedWarning && Reg < HighRegNum)
Bill Wendlinge7176102010-11-06 22:36:58 +0000545 Warning(RegInfo.second,
546 "register not in ascending order in register list");
547
Bill Wendling8e8b18b2010-11-09 23:45:59 +0000548 RegMap[Reg] = true;
549 HighRegNum = std::max(Reg, HighRegNum);
Bill Wendlinge7176102010-11-06 22:36:58 +0000550 }
551
Bill Wendling50d0f582010-11-18 23:43:05 +0000552 Operands.push_back(ARMOperand::CreateRegList(Registers, S, E));
553 return false;
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000554}
555
Bill Wendlinge7176102010-11-06 22:36:58 +0000556/// Parse an ARM memory expression, return false if successful else return true
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000557/// or an error. The first token must be a '[' when called.
Bill Wendling50d0f582010-11-18 23:43:05 +0000558///
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000559/// TODO Only preindexing and postindexing addressing are started, unindexed
560/// with option, etc are still to do.
Bill Wendling50d0f582010-11-18 23:43:05 +0000561bool ARMAsmParser::
562ParseMemory(SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Sean Callanan76264762010-04-02 22:27:05 +0000563 SMLoc S, E;
Sean Callanan18b83232010-01-19 21:44:56 +0000564 assert(Parser.getTok().is(AsmToken::LBrac) &&
Bill Wendlinga60f1572010-11-06 10:48:18 +0000565 "Token is not a Left Bracket");
Sean Callanan76264762010-04-02 22:27:05 +0000566 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000567 Parser.Lex(); // Eat left bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000568
Sean Callanan18b83232010-01-19 21:44:56 +0000569 const AsmToken &BaseRegTok = Parser.getTok();
Chris Lattner550276e2010-10-28 20:52:15 +0000570 if (BaseRegTok.isNot(AsmToken::Identifier)) {
571 Error(BaseRegTok.getLoc(), "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000572 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000573 }
Chris Lattnere5658fa2010-10-30 04:09:10 +0000574 int BaseRegNum = TryParseRegister();
575 if (BaseRegNum == -1) {
Chris Lattner550276e2010-10-28 20:52:15 +0000576 Error(BaseRegTok.getLoc(), "register expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000577 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000578 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000579
580 bool Preindexed = false;
581 bool Postindexed = false;
582 bool OffsetIsReg = false;
583 bool Negative = false;
584 bool Writeback = false;
585
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000586 // First look for preindexed address forms, that is after the "[Rn" we now
587 // have to see if the next token is a comma.
Sean Callanan18b83232010-01-19 21:44:56 +0000588 const AsmToken &Tok = Parser.getTok();
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000589 if (Tok.is(AsmToken::Comma)) {
590 Preindexed = true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000591 Parser.Lex(); // Eat comma token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000592 int OffsetRegNum;
593 bool OffsetRegShifted;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000594 enum ShiftType ShiftType;
595 const MCExpr *ShiftAmount;
596 const MCExpr *Offset;
Chris Lattner550276e2010-10-28 20:52:15 +0000597 if (ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType, ShiftAmount,
598 Offset, OffsetIsReg, OffsetRegNum, E))
Bill Wendling50d0f582010-11-18 23:43:05 +0000599 return true;
Sean Callanan18b83232010-01-19 21:44:56 +0000600 const AsmToken &RBracTok = Parser.getTok();
Chris Lattner550276e2010-10-28 20:52:15 +0000601 if (RBracTok.isNot(AsmToken::RBrac)) {
602 Error(RBracTok.getLoc(), "']' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000603 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000604 }
Sean Callanan76264762010-04-02 22:27:05 +0000605 E = RBracTok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000606 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000607
Jim Grosbach03f44a02010-11-29 23:18:01 +0000608
Sean Callanan18b83232010-01-19 21:44:56 +0000609 const AsmToken &ExclaimTok = Parser.getTok();
Bill Wendling50d0f582010-11-18 23:43:05 +0000610 ARMOperand *WBOp = 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000611 if (ExclaimTok.is(AsmToken::Exclaim)) {
Bill Wendling50d0f582010-11-18 23:43:05 +0000612 WBOp = ARMOperand::CreateToken(ExclaimTok.getString(),
613 ExclaimTok.getLoc());
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000614 Writeback = true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000615 Parser.Lex(); // Eat exclaim token
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000616 }
Bill Wendling50d0f582010-11-18 23:43:05 +0000617
618 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, OffsetIsReg, Offset,
619 OffsetRegNum, OffsetRegShifted,
620 ShiftType, ShiftAmount, Preindexed,
621 Postindexed, Negative, Writeback,
622 S, E));
623 if (WBOp)
624 Operands.push_back(WBOp);
625
626 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000627 }
628 // The "[Rn" we have so far was not followed by a comma.
629 else if (Tok.is(AsmToken::RBrac)) {
Jim Grosbach80eb2332010-10-29 17:41:25 +0000630 // If there's anything other than the right brace, this is a post indexing
631 // addressing form.
Sean Callanan76264762010-04-02 22:27:05 +0000632 E = Tok.getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000633 Parser.Lex(); // Eat right bracket token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000634
Kevin Enderbye2a98dd2009-10-15 21:42:45 +0000635 int OffsetRegNum = 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000636 bool OffsetRegShifted = false;
637 enum ShiftType ShiftType;
638 const MCExpr *ShiftAmount;
Chris Lattner14b93852010-10-29 00:27:31 +0000639 const MCExpr *Offset = 0;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000640
Sean Callanan18b83232010-01-19 21:44:56 +0000641 const AsmToken &NextTok = Parser.getTok();
Jim Grosbach03f44a02010-11-29 23:18:01 +0000642
Kevin Enderbye2a98dd2009-10-15 21:42:45 +0000643 if (NextTok.isNot(AsmToken::EndOfStatement)) {
Jim Grosbach80eb2332010-10-29 17:41:25 +0000644 Postindexed = true;
645 Writeback = true;
Bill Wendling50d0f582010-11-18 23:43:05 +0000646
Chris Lattner550276e2010-10-28 20:52:15 +0000647 if (NextTok.isNot(AsmToken::Comma)) {
648 Error(NextTok.getLoc(), "',' expected");
Bill Wendling50d0f582010-11-18 23:43:05 +0000649 return true;
Chris Lattner550276e2010-10-28 20:52:15 +0000650 }
Bill Wendling50d0f582010-11-18 23:43:05 +0000651
Sean Callananb9a25b72010-01-19 20:27:46 +0000652 Parser.Lex(); // Eat comma token.
Bill Wendling50d0f582010-11-18 23:43:05 +0000653
Chris Lattner550276e2010-10-28 20:52:15 +0000654 if (ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType,
Jim Grosbach16c74252010-10-29 14:46:02 +0000655 ShiftAmount, Offset, OffsetIsReg, OffsetRegNum,
Chris Lattner550276e2010-10-28 20:52:15 +0000656 E))
Bill Wendling50d0f582010-11-18 23:43:05 +0000657 return true;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000658 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000659
Bill Wendling50d0f582010-11-18 23:43:05 +0000660 Operands.push_back(ARMOperand::CreateMem(BaseRegNum, OffsetIsReg, Offset,
661 OffsetRegNum, OffsetRegShifted,
662 ShiftType, ShiftAmount, Preindexed,
663 Postindexed, Negative, Writeback,
664 S, E));
665 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000666 }
667
Bill Wendling50d0f582010-11-18 23:43:05 +0000668 return true;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000669}
670
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000671/// Parse the offset of a memory operand after we have seen "[Rn," or "[Rn],"
672/// we will parse the following (were +/- means that a plus or minus is
673/// optional):
674/// +/-Rm
675/// +/-Rm, shift
676/// #offset
677/// we return false on success or an error otherwise.
678bool ARMAsmParser::ParseMemoryOffsetReg(bool &Negative,
Sean Callanan76264762010-04-02 22:27:05 +0000679 bool &OffsetRegShifted,
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000680 enum ShiftType &ShiftType,
681 const MCExpr *&ShiftAmount,
682 const MCExpr *&Offset,
683 bool &OffsetIsReg,
Sean Callanan76264762010-04-02 22:27:05 +0000684 int &OffsetRegNum,
685 SMLoc &E) {
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000686 Negative = false;
687 OffsetRegShifted = false;
688 OffsetIsReg = false;
689 OffsetRegNum = -1;
Sean Callanan18b83232010-01-19 21:44:56 +0000690 const AsmToken &NextTok = Parser.getTok();
Sean Callanan76264762010-04-02 22:27:05 +0000691 E = NextTok.getLoc();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000692 if (NextTok.is(AsmToken::Plus))
Sean Callananb9a25b72010-01-19 20:27:46 +0000693 Parser.Lex(); // Eat plus token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000694 else if (NextTok.is(AsmToken::Minus)) {
695 Negative = true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000696 Parser.Lex(); // Eat minus token
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000697 }
698 // See if there is a register following the "[Rn," or "[Rn]," we have so far.
Sean Callanan18b83232010-01-19 21:44:56 +0000699 const AsmToken &OffsetRegTok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000700 if (OffsetRegTok.is(AsmToken::Identifier)) {
Chris Lattnere5658fa2010-10-30 04:09:10 +0000701 SMLoc CurLoc = OffsetRegTok.getLoc();
702 OffsetRegNum = TryParseRegister();
703 if (OffsetRegNum != -1) {
Chris Lattner550276e2010-10-28 20:52:15 +0000704 OffsetIsReg = true;
Chris Lattnere5658fa2010-10-30 04:09:10 +0000705 E = CurLoc;
Sean Callanan76264762010-04-02 22:27:05 +0000706 }
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000707 }
Jim Grosbachd4462a52010-11-01 16:44:21 +0000708
Bill Wendling12f40e92010-11-06 10:51:53 +0000709 // If we parsed a register as the offset then there can be a shift after that.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000710 if (OffsetRegNum != -1) {
711 // Look for a comma then a shift
Sean Callanan18b83232010-01-19 21:44:56 +0000712 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000713 if (Tok.is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +0000714 Parser.Lex(); // Eat comma token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000715
Sean Callanan18b83232010-01-19 21:44:56 +0000716 const AsmToken &Tok = Parser.getTok();
Sean Callanan76264762010-04-02 22:27:05 +0000717 if (ParseShift(ShiftType, ShiftAmount, E))
Duncan Sands34727662010-07-12 08:16:59 +0000718 return Error(Tok.getLoc(), "shift expected");
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000719 OffsetRegShifted = true;
720 }
721 }
722 else { // the "[Rn," or "[Rn,]" we have so far was not followed by "Rm"
723 // Look for #offset following the "[Rn," or "[Rn],"
Sean Callanan18b83232010-01-19 21:44:56 +0000724 const AsmToken &HashTok = Parser.getTok();
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000725 if (HashTok.isNot(AsmToken::Hash))
726 return Error(HashTok.getLoc(), "'#' expected");
Jim Grosbach16c74252010-10-29 14:46:02 +0000727
Sean Callananb9a25b72010-01-19 20:27:46 +0000728 Parser.Lex(); // Eat hash token.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000729
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000730 if (getParser().ParseExpression(Offset))
731 return true;
Sean Callanan76264762010-04-02 22:27:05 +0000732 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000733 }
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000734 return false;
735}
736
737/// ParseShift as one of these two:
738/// ( lsl | lsr | asr | ror ) , # shift_amount
739/// rrx
740/// and returns true if it parses a shift otherwise it returns false.
Jim Grosbach16c74252010-10-29 14:46:02 +0000741bool ARMAsmParser::ParseShift(ShiftType &St, const MCExpr *&ShiftAmount,
Sean Callanan76264762010-04-02 22:27:05 +0000742 SMLoc &E) {
Sean Callanan18b83232010-01-19 21:44:56 +0000743 const AsmToken &Tok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000744 if (Tok.isNot(AsmToken::Identifier))
745 return true;
Benjamin Kramer38e59892010-07-14 22:38:02 +0000746 StringRef ShiftName = Tok.getString();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000747 if (ShiftName == "lsl" || ShiftName == "LSL")
748 St = Lsl;
749 else if (ShiftName == "lsr" || ShiftName == "LSR")
750 St = Lsr;
751 else if (ShiftName == "asr" || ShiftName == "ASR")
752 St = Asr;
753 else if (ShiftName == "ror" || ShiftName == "ROR")
754 St = Ror;
755 else if (ShiftName == "rrx" || ShiftName == "RRX")
756 St = Rrx;
757 else
758 return true;
Sean Callananb9a25b72010-01-19 20:27:46 +0000759 Parser.Lex(); // Eat shift type token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000760
761 // Rrx stands alone.
762 if (St == Rrx)
763 return false;
764
765 // Otherwise, there must be a '#' and a shift amount.
Sean Callanan18b83232010-01-19 21:44:56 +0000766 const AsmToken &HashTok = Parser.getTok();
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000767 if (HashTok.isNot(AsmToken::Hash))
768 return Error(HashTok.getLoc(), "'#' expected");
Sean Callananb9a25b72010-01-19 20:27:46 +0000769 Parser.Lex(); // Eat hash token.
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000770
771 if (getParser().ParseExpression(ShiftAmount))
772 return true;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000773
774 return false;
775}
776
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000777/// Parse a arm instruction operand. For now this parses the operand regardless
778/// of the mnemonic.
Bill Wendling50d0f582010-11-18 23:43:05 +0000779bool ARMAsmParser::ParseOperand(SmallVectorImpl<MCParsedAsmOperand*> &Operands){
Sean Callanan76264762010-04-02 22:27:05 +0000780 SMLoc S, E;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000781 switch (getLexer().getKind()) {
Bill Wendling146018f2010-11-06 21:42:12 +0000782 default:
783 Error(Parser.getTok().getLoc(), "unexpected token in operand");
Bill Wendling50d0f582010-11-18 23:43:05 +0000784 return true;
785 case AsmToken::Identifier: {
786 if (!TryParseRegisterWithWriteBack(Operands))
787 return false;
Jim Grosbach16c74252010-10-29 14:46:02 +0000788
Kevin Enderby515d5092009-10-15 20:48:48 +0000789 // This was not a register so parse other operands that start with an
790 // identifier (like labels) as expressions and create them as immediates.
791 const MCExpr *IdVal;
Sean Callanan76264762010-04-02 22:27:05 +0000792 S = Parser.getTok().getLoc();
Kevin Enderby515d5092009-10-15 20:48:48 +0000793 if (getParser().ParseExpression(IdVal))
Bill Wendling50d0f582010-11-18 23:43:05 +0000794 return true;
Sean Callanan76264762010-04-02 22:27:05 +0000795 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +0000796 Operands.push_back(ARMOperand::CreateImm(IdVal, S, E));
797 return false;
798 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000799 case AsmToken::LBrac:
Bill Wendling50d0f582010-11-18 23:43:05 +0000800 return ParseMemory(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000801 case AsmToken::LCurly:
Bill Wendling50d0f582010-11-18 23:43:05 +0000802 return ParseRegisterList(Operands);
Kevin Enderbyd7894f12009-10-09 21:12:28 +0000803 case AsmToken::Hash:
Kevin Enderby079469f2009-10-13 23:33:38 +0000804 // #42 -> immediate.
805 // TODO: ":lower16:" and ":upper16:" modifiers after # before immediate
Sean Callanan76264762010-04-02 22:27:05 +0000806 S = Parser.getTok().getLoc();
Sean Callananb9a25b72010-01-19 20:27:46 +0000807 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +0000808 const MCExpr *ImmVal;
809 if (getParser().ParseExpression(ImmVal))
Bill Wendling50d0f582010-11-18 23:43:05 +0000810 return true;
Sean Callanan76264762010-04-02 22:27:05 +0000811 E = SMLoc::getFromPointer(Parser.getTok().getLoc().getPointer() - 1);
Bill Wendling50d0f582010-11-18 23:43:05 +0000812 Operands.push_back(ARMOperand::CreateImm(ImmVal, S, E));
813 return false;
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000814 }
815}
816
Kevin Enderby9c41fa82009-10-30 22:55:57 +0000817/// Parse an arm instruction mnemonic followed by its operands.
Benjamin Kramer38e59892010-07-14 22:38:02 +0000818bool ARMAsmParser::ParseInstruction(StringRef Name, SMLoc NameLoc,
Chris Lattner98986712010-01-14 22:21:20 +0000819 SmallVectorImpl<MCParsedAsmOperand*> &Operands) {
Daniel Dunbar5747b132010-08-11 06:37:16 +0000820 // Create the leading tokens for the mnemonic, split by '.' characters.
821 size_t Start = 0, Next = Name.find('.');
822 StringRef Head = Name.slice(Start, Next);
823
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000824 // Determine the predicate, if any.
825 //
826 // FIXME: We need a way to check whether a prefix supports predication,
827 // otherwise we will end up with an ambiguity for instructions that happen to
828 // end with a predicate name.
Jim Grosbach3df518e2010-10-29 21:56:51 +0000829 // FIXME: Likewise, some arithmetic instructions have an 's' prefix which
830 // indicates to update the condition codes. Those instructions have an
831 // additional immediate operand which encodes the prefix as reg0 or CPSR.
832 // Just checking for a suffix of 's' definitely creates ambiguities; e.g,
833 // the SMMLS instruction.
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000834 unsigned CC = StringSwitch<unsigned>(Head.substr(Head.size()-2))
835 .Case("eq", ARMCC::EQ)
836 .Case("ne", ARMCC::NE)
837 .Case("hs", ARMCC::HS)
838 .Case("lo", ARMCC::LO)
839 .Case("mi", ARMCC::MI)
840 .Case("pl", ARMCC::PL)
841 .Case("vs", ARMCC::VS)
842 .Case("vc", ARMCC::VC)
843 .Case("hi", ARMCC::HI)
844 .Case("ls", ARMCC::LS)
845 .Case("ge", ARMCC::GE)
846 .Case("lt", ARMCC::LT)
847 .Case("gt", ARMCC::GT)
848 .Case("le", ARMCC::LE)
849 .Case("al", ARMCC::AL)
850 .Default(~0U);
Jim Grosbach16c74252010-10-29 14:46:02 +0000851
Chris Lattnerdba34d82010-10-30 04:35:59 +0000852 if (CC == ~0U ||
853 (CC == ARMCC::LS && (Head == "vmls" || Head == "vnmls"))) {
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000854 CC = ARMCC::AL;
Chris Lattnerdba34d82010-10-30 04:35:59 +0000855 } else {
856 Head = Head.slice(0, Head.size() - 2);
Bill Wendling52925b62010-10-29 23:50:21 +0000857 }
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000858
Chris Lattner3a697562010-10-28 17:20:03 +0000859 Operands.push_back(ARMOperand::CreateToken(Head, NameLoc));
Bill Wendling9717fa92010-11-21 10:56:05 +0000860
861 if (Head != "trap")
862 // FIXME: Should only add this operand for predicated instructions
863 Operands.push_back(ARMOperand::CreateCondCode(ARMCC::CondCodes(CC),
864 NameLoc));
Daniel Dunbar345a9a62010-08-11 06:37:20 +0000865
866 // Add the remaining tokens in the mnemonic.
Daniel Dunbar5747b132010-08-11 06:37:16 +0000867 while (Next != StringRef::npos) {
868 Start = Next;
869 Next = Name.find('.', Start + 1);
870 Head = Name.slice(Start, Next);
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000871
Chris Lattner3a697562010-10-28 17:20:03 +0000872 Operands.push_back(ARMOperand::CreateToken(Head, NameLoc));
Daniel Dunbar5747b132010-08-11 06:37:16 +0000873 }
874
875 // Read the remaining operands.
876 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000877 // Read the first operand.
Bill Wendling50d0f582010-11-18 23:43:05 +0000878 if (ParseOperand(Operands)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +0000879 Parser.EatToEndOfStatement();
880 return true;
881 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000882
883 while (getLexer().is(AsmToken::Comma)) {
Sean Callananb9a25b72010-01-19 20:27:46 +0000884 Parser.Lex(); // Eat the comma.
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000885
886 // Parse and remember the operand.
Bill Wendling50d0f582010-11-18 23:43:05 +0000887 if (ParseOperand(Operands)) {
Chris Lattnercbf8a982010-09-11 16:18:25 +0000888 Parser.EatToEndOfStatement();
889 return true;
890 }
Kevin Enderbya7ba3a82009-10-06 22:26:42 +0000891 }
892 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000893
Chris Lattnercbf8a982010-09-11 16:18:25 +0000894 if (getLexer().isNot(AsmToken::EndOfStatement)) {
895 Parser.EatToEndOfStatement();
Chris Lattner34e53142010-09-08 05:10:46 +0000896 return TokError("unexpected token in argument list");
Chris Lattnercbf8a982010-09-11 16:18:25 +0000897 }
Bill Wendling146018f2010-11-06 21:42:12 +0000898
Chris Lattner34e53142010-09-08 05:10:46 +0000899 Parser.Lex(); // Consume the EndOfStatement
Chris Lattner98986712010-01-14 22:21:20 +0000900 return false;
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000901}
902
Chris Lattnerfa42fad2010-10-28 21:28:01 +0000903bool ARMAsmParser::
904MatchAndEmitInstruction(SMLoc IDLoc,
905 SmallVectorImpl<MCParsedAsmOperand*> &Operands,
906 MCStreamer &Out) {
907 MCInst Inst;
908 unsigned ErrorInfo;
Chris Lattnere73d4f82010-10-28 21:41:58 +0000909 switch (MatchInstructionImpl(Operands, Inst, ErrorInfo)) {
910 case Match_Success:
Chris Lattnerfa42fad2010-10-28 21:28:01 +0000911 Out.EmitInstruction(Inst);
912 return false;
Chris Lattnere73d4f82010-10-28 21:41:58 +0000913 case Match_MissingFeature:
914 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
915 return true;
916 case Match_InvalidOperand: {
917 SMLoc ErrorLoc = IDLoc;
918 if (ErrorInfo != ~0U) {
919 if (ErrorInfo >= Operands.size())
920 return Error(IDLoc, "too few operands for instruction");
Jim Grosbach16c74252010-10-29 14:46:02 +0000921
Chris Lattnere73d4f82010-10-28 21:41:58 +0000922 ErrorLoc = ((ARMOperand*)Operands[ErrorInfo])->getStartLoc();
923 if (ErrorLoc == SMLoc()) ErrorLoc = IDLoc;
924 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000925
Chris Lattnere73d4f82010-10-28 21:41:58 +0000926 return Error(ErrorLoc, "invalid operand for instruction");
Chris Lattnerfa42fad2010-10-28 21:28:01 +0000927 }
Chris Lattnere73d4f82010-10-28 21:41:58 +0000928 case Match_MnemonicFail:
929 return Error(IDLoc, "unrecognized instruction mnemonic");
930 }
Jim Grosbach16c74252010-10-29 14:46:02 +0000931
Eric Christopherc223e2b2010-10-29 09:26:59 +0000932 llvm_unreachable("Implement any new match types added!");
Bill Wendling146018f2010-11-06 21:42:12 +0000933 return true;
Chris Lattnerfa42fad2010-10-28 21:28:01 +0000934}
935
Kevin Enderby515d5092009-10-15 20:48:48 +0000936/// ParseDirective parses the arm specific directives
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000937bool ARMAsmParser::ParseDirective(AsmToken DirectiveID) {
938 StringRef IDVal = DirectiveID.getIdentifier();
939 if (IDVal == ".word")
940 return ParseDirectiveWord(4, DirectiveID.getLoc());
Kevin Enderby515d5092009-10-15 20:48:48 +0000941 else if (IDVal == ".thumb")
942 return ParseDirectiveThumb(DirectiveID.getLoc());
943 else if (IDVal == ".thumb_func")
944 return ParseDirectiveThumbFunc(DirectiveID.getLoc());
945 else if (IDVal == ".code")
946 return ParseDirectiveCode(DirectiveID.getLoc());
947 else if (IDVal == ".syntax")
948 return ParseDirectiveSyntax(DirectiveID.getLoc());
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000949 return true;
950}
951
952/// ParseDirectiveWord
953/// ::= .word [ expression (, expression)* ]
954bool ARMAsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
955 if (getLexer().isNot(AsmToken::EndOfStatement)) {
956 for (;;) {
957 const MCExpr *Value;
958 if (getParser().ParseExpression(Value))
959 return true;
960
Chris Lattneraaec2052010-01-19 19:46:13 +0000961 getParser().getStreamer().EmitValue(Value, Size, 0/*addrspace*/);
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000962
963 if (getLexer().is(AsmToken::EndOfStatement))
964 break;
Jim Grosbach16c74252010-10-29 14:46:02 +0000965
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000966 // FIXME: Improve diagnostic.
967 if (getLexer().isNot(AsmToken::Comma))
968 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +0000969 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000970 }
971 }
972
Sean Callananb9a25b72010-01-19 20:27:46 +0000973 Parser.Lex();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +0000974 return false;
975}
976
Kevin Enderby515d5092009-10-15 20:48:48 +0000977/// ParseDirectiveThumb
978/// ::= .thumb
979bool ARMAsmParser::ParseDirectiveThumb(SMLoc L) {
980 if (getLexer().isNot(AsmToken::EndOfStatement))
981 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +0000982 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +0000983
984 // TODO: set thumb mode
985 // TODO: tell the MC streamer the mode
986 // getParser().getStreamer().Emit???();
987 return false;
988}
989
990/// ParseDirectiveThumbFunc
991/// ::= .thumbfunc symbol_name
992bool ARMAsmParser::ParseDirectiveThumbFunc(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +0000993 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +0000994 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
Jim Grosbach83c40182010-11-05 22:11:33 +0000995 return Error(L, "unexpected token in .thumb_func directive");
Jim Grosbach642fc9c2010-11-05 22:33:53 +0000996 StringRef Name = Tok.getString();
Sean Callananb9a25b72010-01-19 20:27:46 +0000997 Parser.Lex(); // Consume the identifier token.
Kevin Enderby515d5092009-10-15 20:48:48 +0000998 if (getLexer().isNot(AsmToken::EndOfStatement))
999 return Error(L, "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001000 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001001
Jim Grosbach642fc9c2010-11-05 22:33:53 +00001002 // Mark symbol as a thumb symbol.
1003 MCSymbol *Func = getParser().getContext().GetOrCreateSymbol(Name);
1004 getParser().getStreamer().EmitThumbFunc(Func);
Kevin Enderby515d5092009-10-15 20:48:48 +00001005 return false;
1006}
1007
1008/// ParseDirectiveSyntax
1009/// ::= .syntax unified | divided
1010bool ARMAsmParser::ParseDirectiveSyntax(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00001011 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00001012 if (Tok.isNot(AsmToken::Identifier))
1013 return Error(L, "unexpected token in .syntax directive");
Benjamin Kramer38e59892010-07-14 22:38:02 +00001014 StringRef Mode = Tok.getString();
Duncan Sands58c86912010-06-29 13:04:35 +00001015 if (Mode == "unified" || Mode == "UNIFIED")
Sean Callananb9a25b72010-01-19 20:27:46 +00001016 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00001017 else if (Mode == "divided" || Mode == "DIVIDED")
Sean Callananb9a25b72010-01-19 20:27:46 +00001018 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001019 else
1020 return Error(L, "unrecognized syntax mode in .syntax directive");
1021
1022 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00001023 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001024 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001025
1026 // TODO tell the MC streamer the mode
1027 // getParser().getStreamer().Emit???();
1028 return false;
1029}
1030
1031/// ParseDirectiveCode
1032/// ::= .code 16 | 32
1033bool ARMAsmParser::ParseDirectiveCode(SMLoc L) {
Sean Callanan18b83232010-01-19 21:44:56 +00001034 const AsmToken &Tok = Parser.getTok();
Kevin Enderby515d5092009-10-15 20:48:48 +00001035 if (Tok.isNot(AsmToken::Integer))
1036 return Error(L, "unexpected token in .code directive");
Sean Callanan18b83232010-01-19 21:44:56 +00001037 int64_t Val = Parser.getTok().getIntVal();
Duncan Sands58c86912010-06-29 13:04:35 +00001038 if (Val == 16)
Sean Callananb9a25b72010-01-19 20:27:46 +00001039 Parser.Lex();
Duncan Sands58c86912010-06-29 13:04:35 +00001040 else if (Val == 32)
Sean Callananb9a25b72010-01-19 20:27:46 +00001041 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001042 else
1043 return Error(L, "invalid operand to .code directive");
1044
1045 if (getLexer().isNot(AsmToken::EndOfStatement))
Sean Callanan18b83232010-01-19 21:44:56 +00001046 return Error(Parser.getTok().getLoc(), "unexpected token in directive");
Sean Callananb9a25b72010-01-19 20:27:46 +00001047 Parser.Lex();
Kevin Enderby515d5092009-10-15 20:48:48 +00001048
Jim Grosbach2a301702010-11-05 22:40:53 +00001049 if (Val == 16)
1050 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code16);
1051 else
1052 getParser().getStreamer().EmitAssemblerFlag(MCAF_Code32);
1053
Kevin Enderby515d5092009-10-15 20:48:48 +00001054 return false;
1055}
1056
Sean Callanan90b70972010-04-07 20:29:34 +00001057extern "C" void LLVMInitializeARMAsmLexer();
1058
Kevin Enderby9c41fa82009-10-30 22:55:57 +00001059/// Force static initialization.
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001060extern "C" void LLVMInitializeARMAsmParser() {
1061 RegisterAsmParser<ARMAsmParser> X(TheARMTarget);
1062 RegisterAsmParser<ARMAsmParser> Y(TheThumbTarget);
Sean Callanan90b70972010-04-07 20:29:34 +00001063 LLVMInitializeARMAsmLexer();
Kevin Enderbyca9c42c2009-09-15 00:27:25 +00001064}
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001065
Chris Lattner0692ee62010-09-06 19:11:01 +00001066#define GET_REGISTER_MATCHER
1067#define GET_MATCHER_IMPLEMENTATION
Daniel Dunbar3483aca2010-08-11 05:24:50 +00001068#include "ARMGenAsmMatcher.inc"