llvm.org GIT mirror llvm / b9a25b7
Propagated the parser-side Lex function's declaration to MCAsmParser, and changed the target-specific AsmParsers to use it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93900 91177308-0d34-0410-b5e6-96231b3b80d8 Sean Callanan 10 years ago
3 changed file(s) with 53 addition(s) and 48 deletion(s). Raw diff Collapse all Expand all
1212 #include "llvm/System/DataTypes.h"
1313
1414 namespace llvm {
15 class AsmToken;
1516 class MCAsmLexer;
1617 class MCContext;
1718 class MCExpr;
4950 /// clients.
5051 virtual bool Error(SMLoc L, const Twine &Msg) = 0;
5152
53 /// Lex - Get the next AsmToken in the stream, possibly handling file
54 /// inclusion first.
55 virtual const AsmToken &Lex() = 0;
56
5257 /// ParseExpression - Parse an arbitrary expression.
5358 ///
5459 /// @param Res - The value of the expression. The result is undefined
231231 RegNum = MatchRegisterName(Tok.getString());
232232 if (RegNum == -1)
233233 return true;
234 getLexer().Lex(); // Eat identifier token.
234 Parser.Lex(); // Eat identifier token.
235235
236236 bool Writeback = false;
237237 if (ParseWriteBack) {
238238 const AsmToken &ExclaimTok = getLexer().getTok();
239239 if (ExclaimTok.is(AsmToken::Exclaim)) {
240240 Writeback = true;
241 getLexer().Lex(); // Eat exclaim token
241 Parser.Lex(); // Eat exclaim token
242242 }
243243 }
244244
252252 bool ARMAsmParser::ParseRegisterList(ARMOperand &Op) {
253253 assert(getLexer().getTok().is(AsmToken::LCurly) &&
254254 "Token is not an Left Curly Brace");
255 getLexer().Lex(); // Eat left curly brace token.
255 Parser.Lex(); // Eat left curly brace token.
256256
257257 const AsmToken &RegTok = getLexer().getTok();
258258 SMLoc RegLoc = RegTok.getLoc();
261261 int RegNum = MatchRegisterName(RegTok.getString());
262262 if (RegNum == -1)
263263 return Error(RegLoc, "register expected");
264 getLexer().Lex(); // Eat identifier token.
264 Parser.Lex(); // Eat identifier token.
265265 unsigned RegList = 1 << RegNum;
266266
267267 int HighRegNum = RegNum;
268268 // TODO ranges like "{Rn-Rm}"
269269 while (getLexer().getTok().is(AsmToken::Comma)) {
270 getLexer().Lex(); // Eat comma token.
270 Parser.Lex(); // Eat comma token.
271271
272272 const AsmToken &RegTok = getLexer().getTok();
273273 SMLoc RegLoc = RegTok.getLoc();
284284 RegList |= 1 << RegNum;
285285 HighRegNum = RegNum;
286286
287 getLexer().Lex(); // Eat identifier token.
287 Parser.Lex(); // Eat identifier token.
288288 }
289289 const AsmToken &RCurlyTok = getLexer().getTok();
290290 if (RCurlyTok.isNot(AsmToken::RCurly))
291291 return Error(RCurlyTok.getLoc(), "'}' expected");
292 getLexer().Lex(); // Eat left curly brace token.
292 Parser.Lex(); // Eat left curly brace token.
293293
294294 return false;
295295 }
301301 bool ARMAsmParser::ParseMemory(ARMOperand &Op) {
302302 assert(getLexer().getTok().is(AsmToken::LBrac) &&
303303 "Token is not an Left Bracket");
304 getLexer().Lex(); // Eat left bracket token.
304 Parser.Lex(); // Eat left bracket token.
305305
306306 const AsmToken &BaseRegTok = getLexer().getTok();
307307 if (BaseRegTok.isNot(AsmToken::Identifier))
321321 const AsmToken &Tok = getLexer().getTok();
322322 if (Tok.is(AsmToken::Comma)) {
323323 Preindexed = true;
324 getLexer().Lex(); // Eat comma token.
324 Parser.Lex(); // Eat comma token.
325325 int OffsetRegNum;
326326 bool OffsetRegShifted;
327327 enum ShiftType ShiftType;
333333 const AsmToken &RBracTok = getLexer().getTok();
334334 if (RBracTok.isNot(AsmToken::RBrac))
335335 return Error(RBracTok.getLoc(), "']' expected");
336 getLexer().Lex(); // Eat right bracket token.
336 Parser.Lex(); // Eat right bracket token.
337337
338338 const AsmToken &ExclaimTok = getLexer().getTok();
339339 if (ExclaimTok.is(AsmToken::Exclaim)) {
340340 Writeback = true;
341 getLexer().Lex(); // Eat exclaim token
341 Parser.Lex(); // Eat exclaim token
342342 }
343343 Op = ARMOperand::CreateMem(BaseRegNum, OffsetIsReg, Offset, OffsetRegNum,
344344 OffsetRegShifted, ShiftType, ShiftAmount,
351351 // the "[Rn".
352352 Postindexed = true;
353353 Writeback = true;
354 getLexer().Lex(); // Eat right bracket token.
354 Parser.Lex(); // Eat right bracket token.
355355
356356 int OffsetRegNum = 0;
357357 bool OffsetRegShifted = false;
363363 if (NextTok.isNot(AsmToken::EndOfStatement)) {
364364 if (NextTok.isNot(AsmToken::Comma))
365365 return Error(NextTok.getLoc(), "',' expected");
366 getLexer().Lex(); // Eat comma token.
366 Parser.Lex(); // Eat comma token.
367367 if(ParseMemoryOffsetReg(Negative, OffsetRegShifted, ShiftType,
368368 ShiftAmount, Offset, OffsetIsReg, OffsetRegNum))
369369 return true;
399399 OffsetRegNum = -1;
400400 const AsmToken &NextTok = getLexer().getTok();
401401 if (NextTok.is(AsmToken::Plus))
402 getLexer().Lex(); // Eat plus token.
402 Parser.Lex(); // Eat plus token.
403403 else if (NextTok.is(AsmToken::Minus)) {
404404 Negative = true;
405 getLexer().Lex(); // Eat minus token
405 Parser.Lex(); // Eat minus token
406406 }
407407 // See if there is a register following the "[Rn," or "[Rn]," we have so far.
408408 const AsmToken &OffsetRegTok = getLexer().getTok();
416416 // Look for a comma then a shift
417417 const AsmToken &Tok = getLexer().getTok();
418418 if (Tok.is(AsmToken::Comma)) {
419 getLexer().Lex(); // Eat comma token.
419 Parser.Lex(); // Eat comma token.
420420
421421 const AsmToken &Tok = getLexer().getTok();
422422 if (ParseShift(ShiftType, ShiftAmount))
429429 const AsmToken &HashTok = getLexer().getTok();
430430 if (HashTok.isNot(AsmToken::Hash))
431431 return Error(HashTok.getLoc(), "'#' expected");
432 getLexer().Lex(); // Eat hash token.
432 Parser.Lex(); // Eat hash token.
433433
434434 if (getParser().ParseExpression(Offset))
435435 return true;
458458 St = Rrx;
459459 else
460460 return true;
461 getLexer().Lex(); // Eat shift type token.
461 Parser.Lex(); // Eat shift type token.
462462
463463 // Rrx stands alone.
464464 if (St == Rrx)
468468 const AsmToken &HashTok = getLexer().getTok();
469469 if (HashTok.isNot(AsmToken::Hash))
470470 return Error(HashTok.getLoc(), "'#' expected");
471 getLexer().Lex(); // Eat hash token.
471 Parser.Lex(); // Eat hash token.
472472
473473 if (getParser().ParseExpression(ShiftAmount))
474474 return true;
568568 case AsmToken::Hash:
569569 // #42 -> immediate.
570570 // TODO: ":lower16:" and ":upper16:" modifiers after # before immediate
571 getLexer().Lex();
571 Parser.Lex();
572572 const MCExpr *ImmVal;
573573 if (getParser().ParseExpression(ImmVal))
574574 return true;
593593 Operands.push_back(new ARMOperand(Op));
594594
595595 while (getLexer().is(AsmToken::Comma)) {
596 getLexer().Lex(); // Eat the comma.
596 Parser.Lex(); // Eat the comma.
597597
598598 // Parse and remember the operand.
599599 if (ParseOperand(Op)) return true;
636636 // FIXME: Improve diagnostic.
637637 if (getLexer().isNot(AsmToken::Comma))
638638 return Error(L, "unexpected token in directive");
639 getLexer().Lex();
639 Parser.Lex();
640640 }
641641 }
642642
643 getLexer().Lex();
643 Parser.Lex();
644644 return false;
645645 }
646646
649649 bool ARMAsmParser::ParseDirectiveThumb(SMLoc L) {
650650 if (getLexer().isNot(AsmToken::EndOfStatement))
651651 return Error(L, "unexpected token in directive");
652 getLexer().Lex();
652 Parser.Lex();
653653
654654 // TODO: set thumb mode
655655 // TODO: tell the MC streamer the mode
664664 if (Tok.isNot(AsmToken::Identifier) && Tok.isNot(AsmToken::String))
665665 return Error(L, "unexpected token in .syntax directive");
666666 StringRef ATTRIBUTE_UNUSED SymbolName = getLexer().getTok().getIdentifier();
667 getLexer().Lex(); // Consume the identifier token.
667 Parser.Lex(); // Consume the identifier token.
668668
669669 if (getLexer().isNot(AsmToken::EndOfStatement))
670670 return Error(L, "unexpected token in directive");
671 getLexer().Lex();
671 Parser.Lex();
672672
673673 // TODO: mark symbol as a thumb symbol
674674 // getParser().getStreamer().Emit???();
684684 const StringRef &Mode = Tok.getString();
685685 bool unified_syntax;
686686 if (Mode == "unified" || Mode == "UNIFIED") {
687 getLexer().Lex();
687 Parser.Lex();
688688 unified_syntax = true;
689689 }
690690 else if (Mode == "divided" || Mode == "DIVIDED") {
691 getLexer().Lex();
691 Parser.Lex();
692692 unified_syntax = false;
693693 }
694694 else
696696
697697 if (getLexer().isNot(AsmToken::EndOfStatement))
698698 return Error(getLexer().getTok().getLoc(), "unexpected token in directive");
699 getLexer().Lex();
699 Parser.Lex();
700700
701701 // TODO tell the MC streamer the mode
702702 // getParser().getStreamer().Emit???();
712712 int64_t Val = getLexer().getTok().getIntVal();
713713 bool thumb_mode;
714714 if (Val == 16) {
715 getLexer().Lex();
715 Parser.Lex();
716716 thumb_mode = true;
717717 }
718718 else if (Val == 32) {
719 getLexer().Lex();
719 Parser.Lex();
720720 thumb_mode = false;
721721 }
722722 else
724724
725725 if (getLexer().isNot(AsmToken::EndOfStatement))
726726 return Error(getLexer().getTok().getLoc(), "unexpected token in directive");
727 getLexer().Lex();
727 Parser.Lex();
728728
729729 // TODO tell the MC streamer the mode
730730 // getParser().getStreamer().Emit???();
247247 const AsmToken &TokPercent = getLexer().getTok();
248248 assert(TokPercent.is(AsmToken::Percent) && "Invalid token kind!");
249249 StartLoc = TokPercent.getLoc();
250 getLexer().Lex(); // Eat percent token.
250 Parser.Lex(); // Eat percent token.
251251
252252 const AsmToken &Tok = getLexer().getTok();
253253 if (Tok.isNot(AsmToken::Identifier))
260260 return Error(Tok.getLoc(), "invalid register name");
261261
262262 EndLoc = Tok.getLoc();
263 getLexer().Lex(); // Eat identifier token.
263 Parser.Lex(); // Eat identifier token.
264264 return false;
265265 }
266266
279279 case AsmToken::Dollar: {
280280 // $42 -> immediate.
281281 SMLoc Start = getLexer().getTok().getLoc(), End;
282 getLexer().Lex();
282 Parser.Lex();
283283 const MCExpr *Val;
284284 if (getParser().ParseExpression(Val, End))
285285 return 0;
314314 }
315315
316316 // Eat the '('.
317 getLexer().Lex();
317 Parser.Lex();
318318 } else {
319319 // Okay, we have a '('. We don't know if this is an expression or not, but
320320 // so we have to eat the ( to see beyond it.
321321 SMLoc LParenLoc = getLexer().getTok().getLoc();
322 getLexer().Lex(); // Eat the '('.
322 Parser.Lex(); // Eat the '('.
323323
324324 if (getLexer().is(AsmToken::Percent) || getLexer().is(AsmToken::Comma)) {
325325 // Nothing to do here, fall into the code below with the '(' part of the
341341 }
342342
343343 // Eat the '('.
344 getLexer().Lex();
344 Parser.Lex();
345345 }
346346 }
347347
355355 }
356356
357357 if (getLexer().is(AsmToken::Comma)) {
358 getLexer().Lex(); // Eat the comma.
358 Parser.Lex(); // Eat the comma.
359359
360360 // Following the comma we should have either an index register, or a scale
361361 // value. We don't support the later form, but we want to parse it
375375 "expected comma in scale expression");
376376 return 0;
377377 }
378 getLexer().Lex(); // Eat the comma.
378 Parser.Lex(); // Eat the comma.
379379
380380 if (getLexer().isNot(AsmToken::RParen)) {
381381 SMLoc Loc = getLexer().getTok().getLoc();
412412 return 0;
413413 }
414414 SMLoc MemEnd = getLexer().getTok().getLoc();
415 getLexer().Lex(); // Eat the ')'.
415 Parser.Lex(); // Eat the ')'.
416416
417417 return X86Operand::CreateMem(SegReg, Disp, BaseReg, IndexReg, Scale,
418418 MemStart, MemEnd);
430430 if (getLexer().is(AsmToken::Star)) {
431431 SMLoc Loc = getLexer().getTok().getLoc();
432432 Operands.push_back(X86Operand::CreateToken("*", Loc));
433 getLexer().Lex(); // Eat the star.
433 Parser.Lex(); // Eat the star.
434434 }
435435
436436 // Read the first operand.
440440 return true;
441441
442442 while (getLexer().is(AsmToken::Comma)) {
443 getLexer().Lex(); // Eat the comma.
443 Parser.Lex(); // Eat the comma.
444444
445445 // Parse and remember the operand.
446446 if (X86Operand *Op = ParseOperand())
477477 // FIXME: Improve diagnostic.
478478 if (getLexer().isNot(AsmToken::Comma))
479479 return Error(L, "unexpected token in directive");
480 getLexer().Lex();
481 }
482 }
483
484 getLexer().Lex();
480 Parser.Lex();
481 }
482 }
483
484 Parser.Lex();
485485 return false;
486486 }
487487