1 //===- AsmLexer.cpp - Lexer for Assembly Files ----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class implements the lexer for assembly files.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/MC/MCParser/AsmLexer.h"
15 #include "llvm/ADT/APInt.h"
16 #include "llvm/ADT/ArrayRef.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/ADT/StringSwitch.h"
20 #include "llvm/MC/MCAsmInfo.h"
21 #include "llvm/MC/MCParser/MCAsmLexer.h"
22 #include "llvm/Support/SMLoc.h"
23 #include "llvm/Support/SaveAndRestore.h"
34 AsmLexer::AsmLexer(const MCAsmInfo &MAI) : MAI(MAI) {
35 AllowAtInIdentifier = !StringRef(MAI.getCommentString()).startswith("@");
38 AsmLexer::~AsmLexer() = default;
40 void AsmLexer::setBuffer(StringRef Buf, const char *ptr) {
46 CurPtr = CurBuf.begin();
51 /// ReturnError - Set the error to the specified string at the specified
52 /// location. This is defined to always return AsmToken::Error.
53 AsmToken AsmLexer::ReturnError(const char *Loc, const std::string &Msg) {
54 SetError(SMLoc::getFromPointer(Loc), Msg);
56 return AsmToken(AsmToken::Error, StringRef(Loc, CurPtr - Loc));
59 int AsmLexer::getNextChar() {
60 if (CurPtr == CurBuf.end())
62 return (unsigned char)*CurPtr++;
65 /// LexFloatLiteral: [0-9]*[.][0-9]*([eE][+-]?[0-9]*)?
67 /// The leading integral digit sequence and dot should have already been
68 /// consumed, some or all of the fractional digit sequence *can* have been
70 AsmToken AsmLexer::LexFloatLiteral() {
71 // Skip the fractional digit sequence.
72 while (isDigit(*CurPtr))
75 // Check for exponent; we intentionally accept a slighlty wider set of
76 // literals here and rely on the upstream client to reject invalid ones (e.g.,
78 if (*CurPtr == 'e' || *CurPtr == 'E') {
80 if (*CurPtr == '-' || *CurPtr == '+')
82 while (isDigit(*CurPtr))
86 return AsmToken(AsmToken::Real,
87 StringRef(TokStart, CurPtr - TokStart));
90 /// LexHexFloatLiteral matches essentially (.[0-9a-fA-F]*)?[pP][+-]?[0-9a-fA-F]+
91 /// while making sure there are enough actual digits around for the constant to
94 /// The leading "0x[0-9a-fA-F]*" (i.e. integer part) has already been consumed
95 /// before we get here.
96 AsmToken AsmLexer::LexHexFloatLiteral(bool NoIntDigits) {
97 assert((*CurPtr == 'p' || *CurPtr == 'P' || *CurPtr == '.') &&
98 "unexpected parse state in floating hex");
99 bool NoFracDigits = true;
101 // Skip the fractional part if there is one
102 if (*CurPtr == '.') {
105 const char *FracStart = CurPtr;
106 while (isHexDigit(*CurPtr))
109 NoFracDigits = CurPtr == FracStart;
112 if (NoIntDigits && NoFracDigits)
113 return ReturnError(TokStart, "invalid hexadecimal floating-point constant: "
114 "expected at least one significand digit");
116 // Make sure we do have some kind of proper exponent part
117 if (*CurPtr != 'p' && *CurPtr != 'P')
118 return ReturnError(TokStart, "invalid hexadecimal floating-point constant: "
119 "expected exponent part 'p'");
122 if (*CurPtr == '+' || *CurPtr == '-')
125 // N.b. exponent digits are *not* hex
126 const char *ExpStart = CurPtr;
127 while (isDigit(*CurPtr))
130 if (CurPtr == ExpStart)
131 return ReturnError(TokStart, "invalid hexadecimal floating-point constant: "
132 "expected at least one exponent digit");
134 return AsmToken(AsmToken::Real, StringRef(TokStart, CurPtr - TokStart));
137 /// LexIdentifier: [a-zA-Z_.][a-zA-Z0-9_$.@?]*
138 static bool IsIdentifierChar(char c, bool AllowAt) {
139 return isAlnum(c) || c == '_' || c == '$' || c == '.' ||
140 (c == '@' && AllowAt) || c == '?';
143 AsmToken AsmLexer::LexIdentifier() {
144 // Check for floating point literals.
145 if (CurPtr[-1] == '.' && isDigit(*CurPtr)) {
146 // Disambiguate a .1243foo identifier from a floating literal.
147 while (isDigit(*CurPtr))
149 if (*CurPtr == 'e' || *CurPtr == 'E' ||
150 !IsIdentifierChar(*CurPtr, AllowAtInIdentifier))
151 return LexFloatLiteral();
154 while (IsIdentifierChar(*CurPtr, AllowAtInIdentifier))
157 // Handle . as a special case.
158 if (CurPtr == TokStart+1 && TokStart[0] == '.')
159 return AsmToken(AsmToken::Dot, StringRef(TokStart, 1));
161 return AsmToken(AsmToken::Identifier, StringRef(TokStart, CurPtr - TokStart));
164 /// LexSlash: Slash: /
165 /// C-Style Comment: /* ... */
166 AsmToken AsmLexer::LexSlash() {
169 IsAtStartOfStatement = false;
170 break; // C style comment.
173 return LexLineComment();
175 IsAtStartOfStatement = false;
176 return AsmToken(AsmToken::Slash, StringRef(TokStart, 1));
180 ++CurPtr; // skip the star.
181 const char *CommentTextStart = CurPtr;
182 while (CurPtr != CurBuf.end()) {
185 // End of the comment?
188 // If we have a CommentConsumer, notify it about the comment.
189 if (CommentConsumer) {
190 CommentConsumer->HandleComment(
191 SMLoc::getFromPointer(CommentTextStart),
192 StringRef(CommentTextStart, CurPtr - 1 - CommentTextStart));
194 ++CurPtr; // End the */.
195 return AsmToken(AsmToken::Comment,
196 StringRef(TokStart, CurPtr - TokStart));
199 return ReturnError(TokStart, "unterminated comment");
202 /// LexLineComment: Comment: #[^\n]*
204 AsmToken AsmLexer::LexLineComment() {
205 // Mark This as an end of statement with a body of the
206 // comment. While it would be nicer to leave this two tokens,
207 // backwards compatability with TargetParsers makes keeping this in this form
209 const char *CommentTextStart = CurPtr;
210 int CurChar = getNextChar();
211 while (CurChar != '\n' && CurChar != '\r' && CurChar != EOF)
212 CurChar = getNextChar();
213 if (CurChar == '\r' && CurPtr != CurBuf.end() && *CurPtr == '\n')
216 // If we have a CommentConsumer, notify it about the comment.
217 if (CommentConsumer) {
218 CommentConsumer->HandleComment(
219 SMLoc::getFromPointer(CommentTextStart),
220 StringRef(CommentTextStart, CurPtr - 1 - CommentTextStart));
223 IsAtStartOfLine = true;
224 // This is a whole line comment. leave newline
225 if (IsAtStartOfStatement)
226 return AsmToken(AsmToken::EndOfStatement,
227 StringRef(TokStart, CurPtr - TokStart));
228 IsAtStartOfStatement = true;
230 return AsmToken(AsmToken::EndOfStatement,
231 StringRef(TokStart, CurPtr - 1 - TokStart));
234 static void SkipIgnoredIntegerSuffix(const char *&CurPtr) {
235 // Skip ULL, UL, U, L and LL suffices.
236 if (CurPtr[0] == 'U')
238 if (CurPtr[0] == 'L')
240 if (CurPtr[0] == 'L')
244 // Look ahead to search for first non-hex digit, if it's [hH], then we treat the
245 // integer as a hexadecimal, possibly with leading zeroes.
246 static unsigned doLookAhead(const char *&CurPtr, unsigned DefaultRadix) {
247 const char *FirstHex = nullptr;
248 const char *LookAhead = CurPtr;
250 if (isDigit(*LookAhead)) {
252 } else if (isHexDigit(*LookAhead)) {
254 FirstHex = LookAhead;
260 bool isHex = *LookAhead == 'h' || *LookAhead == 'H';
261 CurPtr = isHex || !FirstHex ? LookAhead : FirstHex;
267 static AsmToken intToken(StringRef Ref, APInt &Value)
269 if (Value.isIntN(64))
270 return AsmToken(AsmToken::Integer, Ref, Value);
271 return AsmToken(AsmToken::BigNum, Ref, Value);
274 /// LexDigit: First character is [0-9].
275 /// Local Label: [0-9][:]
276 /// Forward/Backward Label: [0-9][fb]
277 /// Binary integer: 0b[01]+
278 /// Octal integer: 0[0-7]+
279 /// Hex integer: 0x[0-9a-fA-F]+ or [0x]?[0-9][0-9a-fA-F]*[hH]
280 /// Decimal integer: [1-9][0-9]*
281 AsmToken AsmLexer::LexDigit() {
282 // MASM-flavor binary integer: [01]+[bB]
283 // MASM-flavor hexadecimal integer: [0-9][0-9a-fA-F]*[hH]
284 if (IsParsingMSInlineAsm && isdigit(CurPtr[-1])) {
285 const char *FirstNonBinary = (CurPtr[-1] != '0' && CurPtr[-1] != '1') ?
286 CurPtr - 1 : nullptr;
287 const char *OldCurPtr = CurPtr;
288 while (isHexDigit(*CurPtr)) {
289 if (*CurPtr != '0' && *CurPtr != '1' && !FirstNonBinary)
290 FirstNonBinary = CurPtr;
295 if (*CurPtr == 'h' || *CurPtr == 'H') {
296 // hexadecimal number
299 } else if (FirstNonBinary && FirstNonBinary + 1 == CurPtr &&
300 (*FirstNonBinary == 'b' || *FirstNonBinary == 'B'))
303 if (Radix == 2 || Radix == 16) {
304 StringRef Result(TokStart, CurPtr - TokStart);
305 APInt Value(128, 0, true);
307 if (Result.drop_back().getAsInteger(Radix, Value))
308 return ReturnError(TokStart, Radix == 2 ? "invalid binary number" :
309 "invalid hexdecimal number");
311 // MSVC accepts and ignores type suffices on integer literals.
312 SkipIgnoredIntegerSuffix(CurPtr);
314 return intToken(Result, Value);
317 // octal/decimal integers, or floating point numbers, fall through
321 // Decimal integer: [1-9][0-9]*
322 if (CurPtr[-1] != '0' || CurPtr[0] == '.') {
323 unsigned Radix = doLookAhead(CurPtr, 10);
324 bool isHex = Radix == 16;
325 // Check for floating point literals.
326 if (!isHex && (*CurPtr == '.' || *CurPtr == 'e')) {
328 return LexFloatLiteral();
331 StringRef Result(TokStart, CurPtr - TokStart);
333 APInt Value(128, 0, true);
334 if (Result.getAsInteger(Radix, Value))
335 return ReturnError(TokStart, !isHex ? "invalid decimal number" :
336 "invalid hexdecimal number");
338 // Consume the [bB][hH].
339 if (Radix == 2 || Radix == 16)
342 // The darwin/x86 (and x86-64) assembler accepts and ignores type
343 // suffices on integer literals.
344 SkipIgnoredIntegerSuffix(CurPtr);
346 return intToken(Result, Value);
349 if (!IsParsingMSInlineAsm && ((*CurPtr == 'b') || (*CurPtr == 'B'))) {
351 // See if we actually have "0b" as part of something like "jmp 0b\n"
352 if (!isDigit(CurPtr[0])) {
354 StringRef Result(TokStart, CurPtr - TokStart);
355 return AsmToken(AsmToken::Integer, Result, 0);
357 const char *NumStart = CurPtr;
358 while (CurPtr[0] == '0' || CurPtr[0] == '1')
361 // Requires at least one binary digit.
362 if (CurPtr == NumStart)
363 return ReturnError(TokStart, "invalid binary number");
365 StringRef Result(TokStart, CurPtr - TokStart);
367 APInt Value(128, 0, true);
368 if (Result.substr(2).getAsInteger(2, Value))
369 return ReturnError(TokStart, "invalid binary number");
371 // The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL
372 // suffixes on integer literals.
373 SkipIgnoredIntegerSuffix(CurPtr);
375 return intToken(Result, Value);
378 if ((*CurPtr == 'x') || (*CurPtr == 'X')) {
380 const char *NumStart = CurPtr;
381 while (isHexDigit(CurPtr[0]))
384 // "0x.0p0" is valid, and "0x0p0" (but not "0xp0" for example, which will be
385 // diagnosed by LexHexFloatLiteral).
386 if (CurPtr[0] == '.' || CurPtr[0] == 'p' || CurPtr[0] == 'P')
387 return LexHexFloatLiteral(NumStart == CurPtr);
389 // Otherwise requires at least one hex digit.
390 if (CurPtr == NumStart)
391 return ReturnError(CurPtr-2, "invalid hexadecimal number");
393 APInt Result(128, 0);
394 if (StringRef(TokStart, CurPtr - TokStart).getAsInteger(0, Result))
395 return ReturnError(TokStart, "invalid hexadecimal number");
397 // Consume the optional [hH].
398 if (!IsParsingMSInlineAsm && (*CurPtr == 'h' || *CurPtr == 'H'))
401 // The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL
402 // suffixes on integer literals.
403 SkipIgnoredIntegerSuffix(CurPtr);
405 return intToken(StringRef(TokStart, CurPtr - TokStart), Result);
408 // Either octal or hexadecimal.
409 APInt Value(128, 0, true);
410 unsigned Radix = doLookAhead(CurPtr, 8);
411 bool isHex = Radix == 16;
412 StringRef Result(TokStart, CurPtr - TokStart);
413 if (Result.getAsInteger(Radix, Value))
414 return ReturnError(TokStart, !isHex ? "invalid octal number" :
415 "invalid hexdecimal number");
421 // The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL
422 // suffixes on integer literals.
423 SkipIgnoredIntegerSuffix(CurPtr);
425 return intToken(Result, Value);
428 /// LexSingleQuote: Integer: 'b'
429 AsmToken AsmLexer::LexSingleQuote() {
430 int CurChar = getNextChar();
433 CurChar = getNextChar();
436 return ReturnError(TokStart, "unterminated single quote");
438 CurChar = getNextChar();
441 return ReturnError(TokStart, "single quote way too long");
443 // The idea here being that 'c' is basically just an integral
445 StringRef Res = StringRef(TokStart,CurPtr - TokStart);
448 if (Res.startswith("\'\\")) {
449 char theChar = Res[2];
451 default: Value = theChar; break;
452 case '\'': Value = '\''; break;
453 case 't': Value = '\t'; break;
454 case 'n': Value = '\n'; break;
455 case 'b': Value = '\b'; break;
460 return AsmToken(AsmToken::Integer, Res, Value);
463 /// LexQuote: String: "..."
464 AsmToken AsmLexer::LexQuote() {
465 int CurChar = getNextChar();
466 // TODO: does gas allow multiline string constants?
467 while (CurChar != '"') {
468 if (CurChar == '\\') {
470 CurChar = getNextChar();
474 return ReturnError(TokStart, "unterminated string constant");
476 CurChar = getNextChar();
479 return AsmToken(AsmToken::String, StringRef(TokStart, CurPtr - TokStart));
482 StringRef AsmLexer::LexUntilEndOfStatement() {
485 while (!isAtStartOfComment(CurPtr) && // Start of line comment.
486 !isAtStatementSeparator(CurPtr) && // End of statement marker.
487 *CurPtr != '\n' && *CurPtr != '\r' && CurPtr != CurBuf.end()) {
490 return StringRef(TokStart, CurPtr-TokStart);
493 StringRef AsmLexer::LexUntilEndOfLine() {
496 while (*CurPtr != '\n' && *CurPtr != '\r' && CurPtr != CurBuf.end()) {
499 return StringRef(TokStart, CurPtr-TokStart);
502 size_t AsmLexer::peekTokens(MutableArrayRef<AsmToken> Buf,
503 bool ShouldSkipSpace) {
504 SaveAndRestore<const char *> SavedTokenStart(TokStart);
505 SaveAndRestore<const char *> SavedCurPtr(CurPtr);
506 SaveAndRestore<bool> SavedAtStartOfLine(IsAtStartOfLine);
507 SaveAndRestore<bool> SavedAtStartOfStatement(IsAtStartOfStatement);
508 SaveAndRestore<bool> SavedSkipSpace(SkipSpace, ShouldSkipSpace);
509 SaveAndRestore<bool> SavedIsPeeking(IsPeeking, true);
510 std::string SavedErr = getErr();
511 SMLoc SavedErrLoc = getErrLoc();
514 for (ReadCount = 0; ReadCount < Buf.size(); ++ReadCount) {
515 AsmToken Token = LexToken();
517 Buf[ReadCount] = Token;
519 if (Token.is(AsmToken::Eof))
523 SetError(SavedErrLoc, SavedErr);
527 bool AsmLexer::isAtStartOfComment(const char *Ptr) {
528 StringRef CommentString = MAI.getCommentString();
530 if (CommentString.size() == 1)
531 return CommentString[0] == Ptr[0];
533 // Allow # preprocessor commments also be counted as comments for "##" cases
534 if (CommentString[1] == '#')
535 return CommentString[0] == Ptr[0];
537 return strncmp(Ptr, CommentString.data(), CommentString.size()) == 0;
540 bool AsmLexer::isAtStatementSeparator(const char *Ptr) {
541 return strncmp(Ptr, MAI.getSeparatorString(),
542 strlen(MAI.getSeparatorString())) == 0;
545 AsmToken AsmLexer::LexToken() {
547 // This always consumes at least one character.
548 int CurChar = getNextChar();
550 if (!IsPeeking && CurChar == '#' && IsAtStartOfStatement) {
551 // If this starts with a '#', this may be a cpp
552 // hash directive and otherwise a line comment.
553 AsmToken TokenBuf[2];
554 MutableArrayRef<AsmToken> Buf(TokenBuf, 2);
555 size_t num = peekTokens(Buf, true);
556 // There cannot be a space preceeding this
557 if (IsAtStartOfLine && num == 2 && TokenBuf[0].is(AsmToken::Integer) &&
558 TokenBuf[1].is(AsmToken::String)) {
559 CurPtr = TokStart; // reset curPtr;
560 StringRef s = LexUntilEndOfLine();
563 return AsmToken(AsmToken::HashDirective, s);
565 return LexLineComment();
568 if (isAtStartOfComment(TokStart))
569 return LexLineComment();
571 if (isAtStatementSeparator(TokStart)) {
572 CurPtr += strlen(MAI.getSeparatorString()) - 1;
573 IsAtStartOfLine = true;
574 IsAtStartOfStatement = true;
575 return AsmToken(AsmToken::EndOfStatement,
576 StringRef(TokStart, strlen(MAI.getSeparatorString())));
579 // If we're missing a newline at EOF, make sure we still get an
580 // EndOfStatement token before the Eof token.
581 if (CurChar == EOF && !IsAtStartOfStatement) {
582 IsAtStartOfLine = true;
583 IsAtStartOfStatement = true;
584 return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 1));
586 IsAtStartOfLine = false;
587 bool OldIsAtStartOfStatement = IsAtStartOfStatement;
588 IsAtStartOfStatement = false;
591 // Handle identifier: [a-zA-Z_.][a-zA-Z0-9_$.@]*
592 if (isalpha(CurChar) || CurChar == '_' || CurChar == '.')
593 return LexIdentifier();
595 // Unknown character, emit an error.
596 return ReturnError(TokStart, "invalid character in input");
598 IsAtStartOfLine = true;
599 IsAtStartOfStatement = true;
600 return AsmToken(AsmToken::Eof, StringRef(TokStart, 0));
604 IsAtStartOfStatement = OldIsAtStartOfStatement;
605 while (*CurPtr == ' ' || *CurPtr == '\t')
608 return LexToken(); // Ignore whitespace.
610 return AsmToken(AsmToken::Space, StringRef(TokStart, CurPtr - TokStart));
612 IsAtStartOfLine = true;
613 IsAtStartOfStatement = true;
614 // If this is a CR followed by LF, treat that as one token.
615 if (CurPtr != CurBuf.end() && *CurPtr == '\n')
617 return AsmToken(AsmToken::EndOfStatement,
618 StringRef(TokStart, CurPtr - TokStart));
621 IsAtStartOfLine = true;
622 IsAtStartOfStatement = true;
623 return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 1));
624 case ':': return AsmToken(AsmToken::Colon, StringRef(TokStart, 1));
625 case '+': return AsmToken(AsmToken::Plus, StringRef(TokStart, 1));
626 case '-': return AsmToken(AsmToken::Minus, StringRef(TokStart, 1));
627 case '~': return AsmToken(AsmToken::Tilde, StringRef(TokStart, 1));
628 case '(': return AsmToken(AsmToken::LParen, StringRef(TokStart, 1));
629 case ')': return AsmToken(AsmToken::RParen, StringRef(TokStart, 1));
630 case '[': return AsmToken(AsmToken::LBrac, StringRef(TokStart, 1));
631 case ']': return AsmToken(AsmToken::RBrac, StringRef(TokStart, 1));
632 case '{': return AsmToken(AsmToken::LCurly, StringRef(TokStart, 1));
633 case '}': return AsmToken(AsmToken::RCurly, StringRef(TokStart, 1));
634 case '*': return AsmToken(AsmToken::Star, StringRef(TokStart, 1));
635 case ',': return AsmToken(AsmToken::Comma, StringRef(TokStart, 1));
636 case '$': return AsmToken(AsmToken::Dollar, StringRef(TokStart, 1));
637 case '@': return AsmToken(AsmToken::At, StringRef(TokStart, 1));
638 case '\\': return AsmToken(AsmToken::BackSlash, StringRef(TokStart, 1));
640 if (*CurPtr == '=') {
642 return AsmToken(AsmToken::EqualEqual, StringRef(TokStart, 2));
644 return AsmToken(AsmToken::Equal, StringRef(TokStart, 1));
646 if (*CurPtr == '|') {
648 return AsmToken(AsmToken::PipePipe, StringRef(TokStart, 2));
650 return AsmToken(AsmToken::Pipe, StringRef(TokStart, 1));
651 case '^': return AsmToken(AsmToken::Caret, StringRef(TokStart, 1));
653 if (*CurPtr == '&') {
655 return AsmToken(AsmToken::AmpAmp, StringRef(TokStart, 2));
657 return AsmToken(AsmToken::Amp, StringRef(TokStart, 1));
659 if (*CurPtr == '=') {
661 return AsmToken(AsmToken::ExclaimEqual, StringRef(TokStart, 2));
663 return AsmToken(AsmToken::Exclaim, StringRef(TokStart, 1));
665 if (MAI.hasMipsExpressions()) {
666 AsmToken::TokenKind Operator;
667 unsigned OperatorLength;
669 std::tie(Operator, OperatorLength) =
670 StringSwitch<std::pair<AsmToken::TokenKind, unsigned>>(
672 .StartsWith("call16", {AsmToken::PercentCall16, 7})
673 .StartsWith("call_hi", {AsmToken::PercentCall_Hi, 8})
674 .StartsWith("call_lo", {AsmToken::PercentCall_Lo, 8})
675 .StartsWith("dtprel_hi", {AsmToken::PercentDtprel_Hi, 10})
676 .StartsWith("dtprel_lo", {AsmToken::PercentDtprel_Lo, 10})
677 .StartsWith("got_disp", {AsmToken::PercentGot_Disp, 9})
678 .StartsWith("got_hi", {AsmToken::PercentGot_Hi, 7})
679 .StartsWith("got_lo", {AsmToken::PercentGot_Lo, 7})
680 .StartsWith("got_ofst", {AsmToken::PercentGot_Ofst, 9})
681 .StartsWith("got_page", {AsmToken::PercentGot_Page, 9})
682 .StartsWith("gottprel", {AsmToken::PercentGottprel, 9})
683 .StartsWith("got", {AsmToken::PercentGot, 4})
684 .StartsWith("gp_rel", {AsmToken::PercentGp_Rel, 7})
685 .StartsWith("higher", {AsmToken::PercentHigher, 7})
686 .StartsWith("highest", {AsmToken::PercentHighest, 8})
687 .StartsWith("hi", {AsmToken::PercentHi, 3})
688 .StartsWith("lo", {AsmToken::PercentLo, 3})
689 .StartsWith("neg", {AsmToken::PercentNeg, 4})
690 .StartsWith("pcrel_hi", {AsmToken::PercentPcrel_Hi, 9})
691 .StartsWith("pcrel_lo", {AsmToken::PercentPcrel_Lo, 9})
692 .StartsWith("tlsgd", {AsmToken::PercentTlsgd, 6})
693 .StartsWith("tlsldm", {AsmToken::PercentTlsldm, 7})
694 .StartsWith("tprel_hi", {AsmToken::PercentTprel_Hi, 9})
695 .StartsWith("tprel_lo", {AsmToken::PercentTprel_Lo, 9})
696 .Default({AsmToken::Percent, 1});
698 if (Operator != AsmToken::Percent) {
699 CurPtr += OperatorLength - 1;
700 return AsmToken(Operator, StringRef(TokStart, OperatorLength));
703 return AsmToken(AsmToken::Percent, StringRef(TokStart, 1));
705 IsAtStartOfStatement = OldIsAtStartOfStatement;
707 case '#': return AsmToken(AsmToken::Hash, StringRef(TokStart, 1));
708 case '\'': return LexSingleQuote();
709 case '"': return LexQuote();
710 case '0': case '1': case '2': case '3': case '4':
711 case '5': case '6': case '7': case '8': case '9':
717 return AsmToken(AsmToken::LessLess, StringRef(TokStart, 2));
720 return AsmToken(AsmToken::LessEqual, StringRef(TokStart, 2));
723 return AsmToken(AsmToken::LessGreater, StringRef(TokStart, 2));
725 return AsmToken(AsmToken::Less, StringRef(TokStart, 1));
731 return AsmToken(AsmToken::GreaterGreater, StringRef(TokStart, 2));
734 return AsmToken(AsmToken::GreaterEqual, StringRef(TokStart, 2));
736 return AsmToken(AsmToken::Greater, StringRef(TokStart, 1));
739 // TODO: Quoted identifiers (objc methods etc)
740 // local labels: [0-9][:]
741 // Forward/backward labels: [0-9][fb]
742 // Integers, fp constants, character constants.