blob: aa04ba60d37778192919893cb34a099c0043f674 [file] [log] [blame]
Daniel Dunbarc7df3cb2009-07-17 20:42:00 +00001//===-- X86AsmParser.cpp - Parse X86 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
Daniel Dunbar0b0441e2009-07-18 23:03:22 +000010#include "X86.h"
Daniel Dunbar78929e52009-07-20 20:01:54 +000011#include "llvm/ADT/SmallVector.h"
Daniel Dunbar14c5bf82009-07-28 22:40:46 +000012#include "llvm/ADT/Twine.h"
Daniel Dunbard80432a2009-07-28 20:47:52 +000013#include "llvm/MC/MCAsmLexer.h"
Daniel Dunbar4b0f4ef2009-07-20 18:55:04 +000014#include "llvm/MC/MCAsmParser.h"
Kevin Enderbyae90d092009-09-10 20:51:44 +000015#include "llvm/MC/MCStreamer.h"
Daniel Dunbar6e966212009-08-31 08:08:38 +000016#include "llvm/MC/MCExpr.h"
Daniel Dunbara54716c2009-07-31 02:32:59 +000017#include "llvm/MC/MCInst.h"
Daniel Dunbar14c5bf82009-07-28 22:40:46 +000018#include "llvm/Support/SourceMgr.h"
Daniel Dunbarc7df3cb2009-07-17 20:42:00 +000019#include "llvm/Target/TargetRegistry.h"
20#include "llvm/Target/TargetAsmParser.h"
21using namespace llvm;
22
23namespace {
Benjamin Kramer264834b2009-07-31 11:35:26 +000024struct X86Operand;
Daniel Dunbar14c5bf82009-07-28 22:40:46 +000025
26class X86ATTAsmParser : public TargetAsmParser {
27 MCAsmParser &Parser;
28
29private:
Daniel Dunbar14c5bf82009-07-28 22:40:46 +000030 MCAsmParser &getParser() const { return Parser; }
31
32 MCAsmLexer &getLexer() const { return Parser.getLexer(); }
33
34 void Warning(SMLoc L, const Twine &Msg) { Parser.Warning(L, Msg); }
35
36 bool Error(SMLoc L, const Twine &Msg) { return Parser.Error(L, Msg); }
37
38 bool ParseRegister(X86Operand &Op);
39
40 bool ParseOperand(X86Operand &Op);
41
42 bool ParseMemOperand(X86Operand &Op);
Kevin Enderbyae90d092009-09-10 20:51:44 +000043
44 bool ParseDirectiveWord(unsigned Size, SMLoc L);
45
Daniel Dunbar85f1b392009-07-29 00:02:19 +000046 /// @name Auto-generated Match Functions
47 /// {
48
Daniel Dunbarfe6759e2009-08-07 08:26:05 +000049 bool MatchInstruction(SmallVectorImpl<X86Operand> &Operands,
50 MCInst &Inst);
51
Daniel Dunbarb0e6abe2009-08-08 21:22:41 +000052 /// MatchRegisterName - Match the given string to a register name, or 0 if
53 /// there is no match.
54 unsigned MatchRegisterName(const StringRef &Name);
Daniel Dunbar85f1b392009-07-29 00:02:19 +000055
56 /// }
Daniel Dunbar14c5bf82009-07-28 22:40:46 +000057
58public:
59 X86ATTAsmParser(const Target &T, MCAsmParser &_Parser)
60 : TargetAsmParser(T), Parser(_Parser) {}
61
62 virtual bool ParseInstruction(const StringRef &Name, MCInst &Inst);
Kevin Enderbyae90d092009-09-10 20:51:44 +000063
64 virtual bool ParseDirective(AsmToken DirectiveID);
Daniel Dunbar14c5bf82009-07-28 22:40:46 +000065};
Chris Lattnere54532b2009-07-29 06:33:53 +000066
67} // end anonymous namespace
68
69
70namespace {
Daniel Dunbar14c5bf82009-07-28 22:40:46 +000071
72/// X86Operand - Instances of this class represent a parsed X86 machine
73/// instruction.
74struct X86Operand {
75 enum {
Daniel Dunbarfe6759e2009-08-07 08:26:05 +000076 Token,
Daniel Dunbar14c5bf82009-07-28 22:40:46 +000077 Register,
78 Immediate,
79 Memory
80 } Kind;
81
82 union {
83 struct {
Daniel Dunbarfe6759e2009-08-07 08:26:05 +000084 const char *Data;
85 unsigned Length;
86 } Tok;
87
88 struct {
Daniel Dunbar14c5bf82009-07-28 22:40:46 +000089 unsigned RegNo;
90 } Reg;
91
92 struct {
Daniel Dunbar6e966212009-08-31 08:08:38 +000093 const MCExpr *Val;
Daniel Dunbar14c5bf82009-07-28 22:40:46 +000094 } Imm;
95
96 struct {
97 unsigned SegReg;
Daniel Dunbar6e966212009-08-31 08:08:38 +000098 const MCExpr *Disp;
Daniel Dunbar14c5bf82009-07-28 22:40:46 +000099 unsigned BaseReg;
100 unsigned IndexReg;
101 unsigned Scale;
102 } Mem;
Daniel Dunbar78929e52009-07-20 20:01:54 +0000103 };
Daniel Dunbarc7df3cb2009-07-17 20:42:00 +0000104
Daniel Dunbarfe6759e2009-08-07 08:26:05 +0000105 StringRef getToken() const {
106 assert(Kind == Token && "Invalid access!");
107 return StringRef(Tok.Data, Tok.Length);
108 }
109
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000110 unsigned getReg() const {
111 assert(Kind == Register && "Invalid access!");
112 return Reg.RegNo;
113 }
Daniel Dunbard80432a2009-07-28 20:47:52 +0000114
Daniel Dunbar6e966212009-08-31 08:08:38 +0000115 const MCExpr *getImm() const {
Daniel Dunbarb7ddef12009-07-31 20:53:16 +0000116 assert(Kind == Immediate && "Invalid access!");
117 return Imm.Val;
118 }
119
Daniel Dunbar6e966212009-08-31 08:08:38 +0000120 const MCExpr *getMemDisp() const {
Daniel Dunbarb7ddef12009-07-31 20:53:16 +0000121 assert(Kind == Memory && "Invalid access!");
122 return Mem.Disp;
123 }
124 unsigned getMemSegReg() const {
125 assert(Kind == Memory && "Invalid access!");
126 return Mem.SegReg;
127 }
128 unsigned getMemBaseReg() const {
129 assert(Kind == Memory && "Invalid access!");
130 return Mem.BaseReg;
131 }
132 unsigned getMemIndexReg() const {
133 assert(Kind == Memory && "Invalid access!");
134 return Mem.IndexReg;
135 }
136 unsigned getMemScale() const {
137 assert(Kind == Memory && "Invalid access!");
138 return Mem.Scale;
139 }
140
Daniel Dunbar378bee92009-08-08 07:50:56 +0000141 bool isToken() const {return Kind == Token; }
Daniel Dunbarfe6759e2009-08-07 08:26:05 +0000142
143 bool isImm() const { return Kind == Immediate; }
144
Daniel Dunbar06d5cb62009-08-09 07:20:21 +0000145 bool isImmSExt8() const {
146 // Accept immediates which fit in 8 bits when sign extended, and
147 // non-absolute immediates.
148 if (!isImm())
149 return false;
150
Daniel Dunbar6e966212009-08-31 08:08:38 +0000151 if (const MCConstantExpr *CE = dyn_cast<MCConstantExpr>(getImm())) {
152 int64_t Value = CE->getValue();
153 return Value == (int64_t) (int8_t) Value;
154 }
Daniel Dunbar06d5cb62009-08-09 07:20:21 +0000155
Daniel Dunbar6e966212009-08-31 08:08:38 +0000156 return true;
Daniel Dunbar06d5cb62009-08-09 07:20:21 +0000157 }
158
Daniel Dunbarfe6759e2009-08-07 08:26:05 +0000159 bool isMem() const { return Kind == Memory; }
160
161 bool isReg() const { return Kind == Register; }
162
Daniel Dunbarb3413d82009-08-10 21:00:45 +0000163 void addRegOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbarfe6759e2009-08-07 08:26:05 +0000164 assert(N == 1 && "Invalid number of operands!");
165 Inst.addOperand(MCOperand::CreateReg(getReg()));
166 }
167
Daniel Dunbarb3413d82009-08-10 21:00:45 +0000168 void addImmOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbarfe6759e2009-08-07 08:26:05 +0000169 assert(N == 1 && "Invalid number of operands!");
Daniel Dunbar6e966212009-08-31 08:08:38 +0000170 Inst.addOperand(MCOperand::CreateExpr(getImm()));
Daniel Dunbarfe6759e2009-08-07 08:26:05 +0000171 }
172
Daniel Dunbarb3413d82009-08-10 21:00:45 +0000173 void addImmSExt8Operands(MCInst &Inst, unsigned N) const {
Daniel Dunbar06d5cb62009-08-09 07:20:21 +0000174 // FIXME: Support user customization of the render method.
175 assert(N == 1 && "Invalid number of operands!");
Daniel Dunbar6e966212009-08-31 08:08:38 +0000176 Inst.addOperand(MCOperand::CreateExpr(getImm()));
Daniel Dunbar06d5cb62009-08-09 07:20:21 +0000177 }
178
Daniel Dunbarb3413d82009-08-10 21:00:45 +0000179 void addMemOperands(MCInst &Inst, unsigned N) const {
Daniel Dunbarfe6759e2009-08-07 08:26:05 +0000180 assert((N == 4 || N == 5) && "Invalid number of operands!");
181
182 Inst.addOperand(MCOperand::CreateReg(getMemBaseReg()));
183 Inst.addOperand(MCOperand::CreateImm(getMemScale()));
184 Inst.addOperand(MCOperand::CreateReg(getMemIndexReg()));
Daniel Dunbar6e966212009-08-31 08:08:38 +0000185 Inst.addOperand(MCOperand::CreateExpr(getMemDisp()));
Daniel Dunbarfe6759e2009-08-07 08:26:05 +0000186
187 // FIXME: What a hack.
188 if (N == 5)
189 Inst.addOperand(MCOperand::CreateReg(getMemSegReg()));
190 }
191
192 static X86Operand CreateToken(StringRef Str) {
193 X86Operand Res;
194 Res.Kind = Token;
195 Res.Tok.Data = Str.data();
196 Res.Tok.Length = Str.size();
197 return Res;
198 }
199
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000200 static X86Operand CreateReg(unsigned RegNo) {
201 X86Operand Res;
202 Res.Kind = Register;
203 Res.Reg.RegNo = RegNo;
204 return Res;
205 }
Daniel Dunbarfe6759e2009-08-07 08:26:05 +0000206
Daniel Dunbar6e966212009-08-31 08:08:38 +0000207 static X86Operand CreateImm(const MCExpr *Val) {
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000208 X86Operand Res;
209 Res.Kind = Immediate;
210 Res.Imm.Val = Val;
211 return Res;
212 }
Daniel Dunbarfe6759e2009-08-07 08:26:05 +0000213
Daniel Dunbar6e966212009-08-31 08:08:38 +0000214 static X86Operand CreateMem(unsigned SegReg, const MCExpr *Disp,
215 unsigned BaseReg, unsigned IndexReg,
216 unsigned Scale) {
Daniel Dunbar24091712009-07-31 22:22:54 +0000217 // We should never just have a displacement, that would be an immediate.
218 assert((SegReg || BaseReg || IndexReg) && "Invalid memory operand!");
219
Daniel Dunbarb7ddef12009-07-31 20:53:16 +0000220 // The scale should always be one of {1,2,4,8}.
221 assert(((Scale == 1 || Scale == 2 || Scale == 4 || Scale == 8)) &&
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000222 "Invalid scale!");
223 X86Operand Res;
224 Res.Kind = Memory;
225 Res.Mem.SegReg = SegReg;
226 Res.Mem.Disp = Disp;
227 Res.Mem.BaseReg = BaseReg;
228 Res.Mem.IndexReg = IndexReg;
229 Res.Mem.Scale = Scale;
230 return Res;
231 }
232};
Daniel Dunbar4b0f4ef2009-07-20 18:55:04 +0000233
Chris Lattnere54532b2009-07-29 06:33:53 +0000234} // end anonymous namespace.
Daniel Dunbard80432a2009-07-28 20:47:52 +0000235
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000236
237bool X86ATTAsmParser::ParseRegister(X86Operand &Op) {
Kevin Enderbye71842b2009-09-03 17:15:07 +0000238 const AsmToken &TokPercent = getLexer().getTok();
Duncan Sandse0a6add2009-09-06 16:27:34 +0000239 (void)TokPercent; // Avoid warning when assertions are disabled.
Kevin Enderbye71842b2009-09-03 17:15:07 +0000240 assert(TokPercent.is(AsmToken::Percent) && "Invalid token kind!");
241 getLexer().Lex(); // Eat percent token.
242
Chris Lattnere54532b2009-07-29 06:33:53 +0000243 const AsmToken &Tok = getLexer().getTok();
Kevin Enderbye71842b2009-09-03 17:15:07 +0000244 assert(TokPercent.is(AsmToken::Identifier) && "Invalid token kind!");
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000245
Daniel Dunbar85f1b392009-07-29 00:02:19 +0000246 // FIXME: Validate register for the current architecture; we have to do
247 // validation later, so maybe there is no need for this here.
248 unsigned RegNo;
Daniel Dunbarb0e6abe2009-08-08 21:22:41 +0000249
Kevin Enderbye71842b2009-09-03 17:15:07 +0000250 RegNo = MatchRegisterName(Tok.getString());
Daniel Dunbarb0e6abe2009-08-08 21:22:41 +0000251 if (RegNo == 0)
Daniel Dunbar85f1b392009-07-29 00:02:19 +0000252 return Error(Tok.getLoc(), "invalid register name");
253
254 Op = X86Operand::CreateReg(RegNo);
Kevin Enderbye71842b2009-09-03 17:15:07 +0000255 getLexer().Lex(); // Eat identifier token.
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000256
257 return false;
Daniel Dunbarc7df3cb2009-07-17 20:42:00 +0000258}
259
Daniel Dunbar78929e52009-07-20 20:01:54 +0000260bool X86ATTAsmParser::ParseOperand(X86Operand &Op) {
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000261 switch (getLexer().getKind()) {
262 default:
263 return ParseMemOperand(Op);
Kevin Enderbye71842b2009-09-03 17:15:07 +0000264 case AsmToken::Percent:
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000265 // FIXME: if a segment register, this could either be just the seg reg, or
266 // the start of a memory operand.
267 return ParseRegister(Op);
268 case AsmToken::Dollar: {
269 // $42 -> immediate.
270 getLexer().Lex();
Daniel Dunbar6e966212009-08-31 08:08:38 +0000271 const MCExpr *Val;
272 if (getParser().ParseExpression(Val))
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000273 return true;
274 Op = X86Operand::CreateImm(Val);
275 return false;
276 }
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000277 }
Daniel Dunbar78929e52009-07-20 20:01:54 +0000278}
279
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000280/// ParseMemOperand: segment: disp(basereg, indexreg, scale)
281bool X86ATTAsmParser::ParseMemOperand(X86Operand &Op) {
282 // FIXME: If SegReg ':' (e.g. %gs:), eat and remember.
283 unsigned SegReg = 0;
284
285 // We have to disambiguate a parenthesized expression "(4+5)" from the start
286 // of a memory operand with a missing displacement "(%ebx)" or "(,%eax)". The
287 // only way to do this without lookahead is to eat the ( and see what is after
288 // it.
Daniel Dunbar6e966212009-08-31 08:08:38 +0000289 const MCExpr *Disp = MCConstantExpr::Create(0, getParser().getContext());
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000290 if (getLexer().isNot(AsmToken::LParen)) {
Daniel Dunbar6e966212009-08-31 08:08:38 +0000291 if (getParser().ParseExpression(Disp)) return true;
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000292
293 // After parsing the base expression we could either have a parenthesized
294 // memory address or not. If not, return now. If so, eat the (.
295 if (getLexer().isNot(AsmToken::LParen)) {
Daniel Dunbar24091712009-07-31 22:22:54 +0000296 // Unless we have a segment register, treat this as an immediate.
297 if (SegReg)
298 Op = X86Operand::CreateMem(SegReg, Disp, 0, 0, 1);
299 else
300 Op = X86Operand::CreateImm(Disp);
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000301 return false;
302 }
303
304 // Eat the '('.
305 getLexer().Lex();
306 } else {
307 // Okay, we have a '('. We don't know if this is an expression or not, but
308 // so we have to eat the ( to see beyond it.
309 getLexer().Lex(); // Eat the '('.
310
Kevin Enderbye71842b2009-09-03 17:15:07 +0000311 if (getLexer().is(AsmToken::Percent) || getLexer().is(AsmToken::Comma)) {
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000312 // Nothing to do here, fall into the code below with the '(' part of the
313 // memory operand consumed.
314 } else {
315 // It must be an parenthesized expression, parse it now.
Daniel Dunbar6e966212009-08-31 08:08:38 +0000316 if (getParser().ParseParenExpression(Disp))
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000317 return true;
318
319 // After parsing the base expression we could either have a parenthesized
320 // memory address or not. If not, return now. If so, eat the (.
321 if (getLexer().isNot(AsmToken::LParen)) {
Daniel Dunbar24091712009-07-31 22:22:54 +0000322 // Unless we have a segment register, treat this as an immediate.
323 if (SegReg)
324 Op = X86Operand::CreateMem(SegReg, Disp, 0, 0, 1);
325 else
326 Op = X86Operand::CreateImm(Disp);
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000327 return false;
328 }
329
330 // Eat the '('.
331 getLexer().Lex();
332 }
333 }
334
335 // If we reached here, then we just ate the ( of the memory operand. Process
336 // the rest of the memory operand.
Daniel Dunbarb7ddef12009-07-31 20:53:16 +0000337 unsigned BaseReg = 0, IndexReg = 0, Scale = 1;
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000338
Kevin Enderbye71842b2009-09-03 17:15:07 +0000339 if (getLexer().is(AsmToken::Percent)) {
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000340 if (ParseRegister(Op))
341 return true;
342 BaseReg = Op.getReg();
343 }
344
345 if (getLexer().is(AsmToken::Comma)) {
346 getLexer().Lex(); // Eat the comma.
347
348 // Following the comma we should have either an index register, or a scale
349 // value. We don't support the later form, but we want to parse it
350 // correctly.
351 //
352 // Not that even though it would be completely consistent to support syntax
353 // like "1(%eax,,1)", the assembler doesn't.
Kevin Enderbye71842b2009-09-03 17:15:07 +0000354 if (getLexer().is(AsmToken::Percent)) {
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000355 if (ParseRegister(Op))
356 return true;
357 IndexReg = Op.getReg();
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000358
359 if (getLexer().isNot(AsmToken::RParen)) {
360 // Parse the scale amount:
361 // ::= ',' [scale-expression]
362 if (getLexer().isNot(AsmToken::Comma))
363 return true;
364 getLexer().Lex(); // Eat the comma.
365
366 if (getLexer().isNot(AsmToken::RParen)) {
367 SMLoc Loc = getLexer().getTok().getLoc();
368
369 int64_t ScaleVal;
370 if (getParser().ParseAbsoluteExpression(ScaleVal))
371 return true;
372
373 // Validate the scale amount.
374 if (ScaleVal != 1 && ScaleVal != 2 && ScaleVal != 4 && ScaleVal != 8)
375 return Error(Loc, "scale factor in address must be 1, 2, 4 or 8");
376 Scale = (unsigned)ScaleVal;
377 }
378 }
379 } else if (getLexer().isNot(AsmToken::RParen)) {
380 // Otherwise we have the unsupported form of a scale amount without an
381 // index.
382 SMLoc Loc = getLexer().getTok().getLoc();
383
384 int64_t Value;
385 if (getParser().ParseAbsoluteExpression(Value))
386 return true;
387
388 return Error(Loc, "cannot have scale factor without index register");
389 }
390 }
391
392 // Ok, we've eaten the memory operand, verify we have a ')' and eat it too.
393 if (getLexer().isNot(AsmToken::RParen))
394 return Error(getLexer().getTok().getLoc(),
395 "unexpected token in memory operand");
396 getLexer().Lex(); // Eat the ')'.
397
398 Op = X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale);
399 return false;
400}
401
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000402bool X86ATTAsmParser::ParseInstruction(const StringRef &Name, MCInst &Inst) {
Daniel Dunbar62beebc2009-08-07 20:33:39 +0000403 SmallVector<X86Operand, 8> Operands;
Daniel Dunbarfe6759e2009-08-07 08:26:05 +0000404
405 Operands.push_back(X86Operand::CreateToken(Name));
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000406
Daniel Dunbara54716c2009-07-31 02:32:59 +0000407 SMLoc Loc = getLexer().getTok().getLoc();
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000408 if (getLexer().isNot(AsmToken::EndOfStatement)) {
Daniel Dunbar76953672009-08-11 05:00:25 +0000409
410 // Parse '*' modifier.
411 if (getLexer().is(AsmToken::Star)) {
412 getLexer().Lex(); // Eat the star.
413 Operands.push_back(X86Operand::CreateToken("*"));
414 }
415
Daniel Dunbar14c5bf82009-07-28 22:40:46 +0000416 // Read the first operand.
417 Operands.push_back(X86Operand());
418 if (ParseOperand(Operands.back()))
419 return true;
420
421 while (getLexer().is(AsmToken::Comma)) {
422 getLexer().Lex(); // Eat the comma.
423
424 // Parse and remember the operand.
425 Operands.push_back(X86Operand());
426 if (ParseOperand(Operands.back()))
427 return true;
428 }
429 }
430
Daniel Dunbarfe6759e2009-08-07 08:26:05 +0000431 if (!MatchInstruction(Operands, Inst))
Daniel Dunbara54716c2009-07-31 02:32:59 +0000432 return false;
433
434 // FIXME: We should give nicer diagnostics about the exact failure.
435
Daniel Dunbar575db962009-08-14 03:48:55 +0000436 Error(Loc, "unrecognized instruction");
437 return true;
Daniel Dunbar4b0f4ef2009-07-20 18:55:04 +0000438}
439
Kevin Enderbyae90d092009-09-10 20:51:44 +0000440bool X86ATTAsmParser::ParseDirective(AsmToken DirectiveID) {
441 StringRef IDVal = DirectiveID.getIdentifier();
442 if (IDVal == ".word")
443 return ParseDirectiveWord(2, DirectiveID.getLoc());
444 return true;
445}
446
447/// ParseDirectiveWord
448/// ::= .word [ expression (, expression)* ]
449bool X86ATTAsmParser::ParseDirectiveWord(unsigned Size, SMLoc L) {
450 if (getLexer().isNot(AsmToken::EndOfStatement)) {
451 for (;;) {
452 const MCExpr *Value;
453 if (getParser().ParseExpression(Value))
454 return true;
455
456 getParser().getStreamer().EmitValue(Value, Size);
457
458 if (getLexer().is(AsmToken::EndOfStatement))
459 break;
460
461 // FIXME: Improve diagnostic.
462 if (getLexer().isNot(AsmToken::Comma))
463 return Error(L, "unexpected token in directive");
464 getLexer().Lex();
465 }
466 }
467
468 getLexer().Lex();
469 return false;
470}
471
Daniel Dunbarc7df3cb2009-07-17 20:42:00 +0000472// Force static initialization.
473extern "C" void LLVMInitializeX86AsmParser() {
Daniel Dunbarc680b012009-07-25 06:49:55 +0000474 RegisterAsmParser<X86ATTAsmParser> X(TheX86_32Target);
475 RegisterAsmParser<X86ATTAsmParser> Y(TheX86_64Target);
Daniel Dunbarc7df3cb2009-07-17 20:42:00 +0000476}
Daniel Dunbar85f1b392009-07-29 00:02:19 +0000477
478#include "X86GenAsmMatcher.inc"