Coverage Report

Created: 2026-07-25 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/keystone/llvm/lib/MC/MCParser/AsmLexer.cpp
Line
Count
Source
1
//===- AsmLexer.cpp - Lexer for Assembly Files ----------------------------===//
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
// This class implements the lexer for assembly files.
11
//
12
//===----------------------------------------------------------------------===//
13
//
14
#include "llvm/MC/MCParser/AsmLexer.h"
15
#include "llvm/MC/MCAsmInfo.h"
16
#include "llvm/Support/MemoryBuffer.h"
17
#include "llvm/Support/SMLoc.h"
18
#include <cctype>
19
#include <cerrno>
20
#include <cstdio>
21
#include <cstdlib>
22
using namespace llvm_ks;
23
24
166k
AsmLexer::AsmLexer(const MCAsmInfo &MAI) : MAI(MAI) {
25
166k
  CurPtr = nullptr;
26
166k
  isAtStartOfLine = true;
27
166k
  AllowAtInIdentifier = !StringRef(MAI.getCommentString()).startswith("@");
28
166k
  defaultRadix = MAI.getRadix();
29
166k
}
30
31
166k
AsmLexer::~AsmLexer() {
32
166k
}
33
34
1.21M
void AsmLexer::setBuffer(StringRef Buf, const char *ptr) {
35
1.21M
  CurBuf = Buf;
36
37
1.21M
  if (ptr)
38
517k
    CurPtr = ptr;
39
693k
  else
40
693k
    CurPtr = CurBuf.begin();
41
42
1.21M
  TokStart = nullptr;
43
1.21M
}
44
45
/// ReturnError - Set the error to the specified string at the specified
46
/// location.  This is defined to always return AsmToken::Error.
47
AsmToken AsmLexer::ReturnError(const char *Loc, const std::string &Msg)
48
22.1M
{
49
  //SetError(SMLoc::getFromPointer(Loc), Msg);
50
51
22.1M
  return AsmToken(AsmToken::Error, StringRef(Loc, 0));
52
22.1M
}
53
54
250M
int AsmLexer::getNextChar() {
55
250M
  char CurChar = *CurPtr++;
56
250M
  switch (CurChar) {
57
249M
  default:
58
249M
    return (unsigned char)CurChar;
59
279k
  case 0:
60
    // A nul character in the stream is either the end of the current buffer or
61
    // a random nul in the file.  Disambiguate that here.
62
279k
    if (CurPtr - 1 != CurBuf.end())
63
0
      return 0;  // Just whitespace.
64
65
    // Otherwise, return end of file.
66
279k
    --CurPtr;  // Another call to lex will return EOF again.
67
279k
    return EOF;
68
250M
  }
69
250M
}
70
71
/// LexFloatLiteral: [0-9]*[.][0-9]*([eE][+-]?[0-9]*)?
72
///
73
/// The leading integral digit sequence and dot should have already been
74
/// consumed, some or all of the fractional digit sequence *can* have been
75
/// consumed.
76
828k
AsmToken AsmLexer::LexFloatLiteral() {
77
  // Skip the fractional digit sequence.
78
828k
  while (isdigit(*CurPtr))
79
0
    ++CurPtr;
80
81
  // Check for exponent; we intentionally accept a slighlty wider set of
82
  // literals here and rely on the upstream client to reject invalid ones (e.g.,
83
  // "1e+").
84
828k
  if (*CurPtr == 'e' || *CurPtr == 'E') {
85
143k
    ++CurPtr;
86
143k
    if (*CurPtr == '-' || *CurPtr == '+')
87
54.6k
      ++CurPtr;
88
510k
    while (isdigit(*CurPtr))
89
366k
      ++CurPtr;
90
143k
  }
91
92
828k
  return AsmToken(AsmToken::Real,
93
828k
                  StringRef(TokStart, CurPtr - TokStart));
94
828k
}
95
96
/// LexHexFloatLiteral matches essentially (.[0-9a-fA-F]*)?[pP][+-]?[0-9a-fA-F]+
97
/// while making sure there are enough actual digits around for the constant to
98
/// be valid.
99
///
100
/// The leading "0x[0-9a-fA-F]*" (i.e. integer part) has already been consumed
101
/// before we get here.
102
AsmToken AsmLexer::LexHexFloatLiteral(bool NoIntDigits)
103
246k
{
104
246k
  assert((*CurPtr == 'p' || *CurPtr == 'P' || *CurPtr == '.') &&
105
246k
         "unexpected parse state in floating hex");
106
246k
  bool NoFracDigits = true;
107
108
  // Skip the fractional part if there is one
109
246k
  if (*CurPtr == '.') {
110
118k
    ++CurPtr;
111
112
118k
    const char *FracStart = CurPtr;
113
568k
    while (isxdigit(*CurPtr))
114
450k
      ++CurPtr;
115
116
118k
    NoFracDigits = CurPtr == FracStart;
117
118k
  }
118
119
246k
  if (NoIntDigits && NoFracDigits)
120
15.8k
    return ReturnError(TokStart, "invalid hexadecimal floating-point constant: "
121
15.8k
                                 "expected at least one significand digit");
122
123
  // Make sure we do have some kind of proper exponent part
124
231k
  if (*CurPtr != 'p' && *CurPtr != 'P')
125
26.0k
    return ReturnError(TokStart, "invalid hexadecimal floating-point constant: "
126
26.0k
                                 "expected exponent part 'p'");
127
205k
  ++CurPtr;
128
129
205k
  if (*CurPtr == '+' || *CurPtr == '-')
130
69.3k
    ++CurPtr;
131
132
  // N.b. exponent digits are *not* hex
133
205k
  const char *ExpStart = CurPtr;
134
643k
  while (isdigit(*CurPtr))
135
438k
    ++CurPtr;
136
137
205k
  if (CurPtr == ExpStart)
138
32.2k
    return ReturnError(TokStart, "invalid hexadecimal floating-point constant: "
139
32.2k
                                 "expected at least one exponent digit");
140
141
172k
  return AsmToken(AsmToken::Real, StringRef(TokStart, CurPtr - TokStart));
142
205k
}
143
144
/// LexIdentifier: [a-zA-Z_.][a-zA-Z0-9_$.@?]*
145
200M
static bool IsIdentifierChar(char c, bool AllowAt) {
146
200M
  return isalnum(c) || c == '_' || c == '$' || c == '.' ||
147
46.0M
         (c == '@' && AllowAt) || c == '?';
148
200M
}
149
45.3M
AsmToken AsmLexer::LexIdentifier() {
150
  // Check for floating point literals.
151
45.3M
  if (CurPtr[-1] == '.' && isdigit(*CurPtr)) {
152
    // Disambiguate a .1243foo identifier from a floating literal.
153
8.08M
    while (isdigit(*CurPtr))
154
6.74M
      ++CurPtr;
155
1.33M
    if (*CurPtr == 'e' || *CurPtr == 'E' ||
156
1.19M
        !IsIdentifierChar(*CurPtr, AllowAtInIdentifier))
157
828k
      return LexFloatLiteral();
158
1.33M
  }
159
160
198M
  while (IsIdentifierChar(*CurPtr, AllowAtInIdentifier))
161
154M
    ++CurPtr;
162
163
  // Handle . as a special case.
164
44.5M
  if (CurPtr == TokStart+1 && TokStart[0] == '.')
165
4.30M
    return AsmToken(AsmToken::Dot, StringRef(TokStart, 1));
166
167
40.2M
  return AsmToken(AsmToken::Identifier, StringRef(TokStart, CurPtr - TokStart));
168
44.5M
}
169
170
/// LexSlash: Slash: /
171
///           C-Style Comment: /* ... */
172
AsmToken AsmLexer::LexSlash()
173
363k
{
174
363k
  switch (*CurPtr) {
175
22.3k
  case '*': break; // C style comment.
176
70.4k
  case '/': return ++CurPtr, LexLineComment();
177
270k
  default:  return AsmToken(AsmToken::Slash, StringRef(CurPtr-1, 1));
178
363k
  }
179
180
  // C Style comment.
181
22.3k
  ++CurPtr;  // skip the star.
182
69.6k
  while (1) {
183
69.6k
    int CurChar = getNextChar();
184
69.6k
    switch (CurChar) {
185
322
    case EOF:
186
322
      return ReturnError(TokStart, "unterminated comment");
187
30.8k
    case '*':
188
      // End of the comment?
189
30.8k
      if (CurPtr[0] != '/') break;
190
191
22.0k
      ++CurPtr;   // End the */.
192
22.0k
      return LexToken();
193
69.6k
    }
194
69.6k
  }
195
22.3k
}
196
197
/// LexLineComment: Comment: #[^\n]*
198
///                        : //[^\n]*
199
590k
AsmToken AsmLexer::LexLineComment() {
200
  // FIXME: This is broken if we happen to a comment at the end of a file, which
201
  // was .included, and which doesn't end with a newline.
202
590k
  int CurChar = getNextChar();
203
11.5M
  while (CurChar != '\n' && CurChar != '\r' && CurChar != EOF)
204
10.9M
    CurChar = getNextChar();
205
206
590k
  if (CurChar == EOF)
207
3.50k
    return AsmToken(AsmToken::Eof, StringRef(TokStart, 0));
208
586k
  return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 0));
209
590k
}
210
211
10.0M
static void SkipIgnoredIntegerSuffix(const char *&CurPtr) {
212
  // Skip ULL, UL, U, L and LL suffices.
213
10.0M
  if (CurPtr[0] == 'U')
214
54.0k
    ++CurPtr;
215
10.0M
  if (CurPtr[0] == 'L')
216
289k
    ++CurPtr;
217
10.0M
  if (CurPtr[0] == 'L')
218
109k
    ++CurPtr;
219
10.0M
}
220
221
// Look ahead to search for first non-hex digit, if it's [hH], then we treat the
222
// integer as a hexadecimal, possibly with leading zeroes.
223
9.93M
static unsigned doLookAhead(const char *&CurPtr, unsigned DefaultRadix) {
224
9.93M
  const char *FirstHex = nullptr;
225
9.93M
  const char *LookAhead = CurPtr;
226
28.4M
  while (1) {
227
28.4M
    if (isdigit(*LookAhead)) {
228
17.6M
      ++LookAhead;
229
17.6M
    } else if (isxdigit(*LookAhead)) {
230
789k
      if (!FirstHex)
231
530k
        FirstHex = LookAhead;
232
789k
      ++LookAhead;
233
9.93M
    } else {
234
9.93M
      break;
235
9.93M
    }
236
28.4M
  }
237
9.93M
  bool isHex = *LookAhead == 'h' || *LookAhead == 'H';
238
9.93M
  CurPtr = isHex || !FirstHex ? LookAhead : FirstHex;
239
9.93M
  if (isHex)
240
30.0k
    return 16;
241
9.90M
  return DefaultRadix;
242
9.93M
}
243
244
static AsmToken intToken(StringRef Ref, APInt &Value)
245
10.0M
{
246
10.0M
  if (Value.isIntN(64))
247
9.93M
    return AsmToken(AsmToken::Integer, Ref, Value);
248
141k
  return AsmToken(AsmToken::BigNum, Ref, Value);
249
10.0M
}
250
251
/// LexDigit: First character is [0-9].
252
///   Local Label: [0-9][:]
253
///   Forward/Backward Label: [0-9][fb]
254
///   Binary integer: 0b[01]+
255
///   Octal integer: 0[0-7]+
256
///   Hex integer: 0x[0-9a-fA-F]+ or [0x]?[0-9][0-9a-fA-F]*[hH]
257
///   Decimal integer: [1-9][0-9]*
258
AsmToken AsmLexer::LexDigit()
259
10.6M
{
260
  // Decimal integer: [1-9][0-9]*
261
10.6M
  if (CurPtr[-1] != '0' || CurPtr[0] == '.') {
262
6.68M
    unsigned Radix = doLookAhead(CurPtr, 10);
263
264
6.68M
    if (defaultRadix == 16)
265
6.68M
      Radix = 16;
266
267
6.68M
    bool isHex = Radix == 16;
268
    // Check for floating point literals.
269
6.68M
    if (!isHex && (*CurPtr == '.' || *CurPtr == 'e')) {
270
0
      ++CurPtr;
271
0
      return LexFloatLiteral();
272
0
    }
273
274
6.68M
    StringRef Result(TokStart, CurPtr - TokStart);
275
276
6.68M
    APInt Value(128, 0, true);
277
6.68M
    if (Result.getAsInteger(Radix, Value))
278
0
      return ReturnError(TokStart, !isHex ? "invalid decimal number" :
279
0
                           "invalid hexdecimal number");
280
281
    // Consume the [bB][hH].
282
6.68M
    if (defaultRadix != 16) {
283
0
      if (Radix == 2 || Radix == 16)
284
0
        ++CurPtr;
285
0
    }
286
287
    // The darwin/x86 (and x86-64) assembler accepts and ignores type
288
    // suffices on integer literals.
289
6.68M
    SkipIgnoredIntegerSuffix(CurPtr);
290
291
6.68M
    return intToken(Result, Value);
292
6.68M
  }
293
294
3.94M
  if (*CurPtr == 'b') {
295
215k
    ++CurPtr;
296
    // See if we actually have "0b" as part of something like "jmp 0b\n"
297
215k
    if (!isdigit(CurPtr[0])) {
298
122k
      --CurPtr;
299
122k
      StringRef Result(TokStart, CurPtr - TokStart);
300
122k
      return AsmToken(AsmToken::Integer, Result, 0);
301
122k
    }
302
92.6k
    const char *NumStart = CurPtr;
303
449k
    while (CurPtr[0] == '0' || CurPtr[0] == '1')
304
357k
      ++CurPtr;
305
306
    // Requires at least one binary digit.
307
92.6k
    if (CurPtr == NumStart)
308
4.39k
      return ReturnError(TokStart, "invalid binary number");
309
310
88.2k
    StringRef Result(TokStart, CurPtr - TokStart);
311
312
88.2k
    APInt Value(128, 0, true);
313
88.2k
    if (Result.substr(2).getAsInteger(2, Value))
314
0
      return ReturnError(TokStart, "invalid binary number");
315
316
    // The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL
317
    // suffixes on integer literals.
318
88.2k
    SkipIgnoredIntegerSuffix(CurPtr);
319
320
88.2k
    return intToken(Result, Value);
321
88.2k
  }
322
323
3.73M
  if (*CurPtr == 'x' || *CurPtr == 'X') {
324
489k
    ++CurPtr;
325
489k
    const char *NumStart = CurPtr;
326
3.15M
    while (isxdigit(CurPtr[0]))
327
2.66M
      ++CurPtr;
328
329
    // "0x.0p0" is valid, and "0x0p0" (but not "0xp0" for example, which will be
330
    // diagnosed by LexHexFloatLiteral).
331
489k
    if (CurPtr[0] == '.' || CurPtr[0] == 'p' || CurPtr[0] == 'P')
332
246k
      return LexHexFloatLiteral(NumStart == CurPtr);
333
334
    // Otherwise requires at least one hex digit.
335
242k
    if (CurPtr == NumStart)
336
24.9k
      return ReturnError(CurPtr-2, "invalid hexadecimal number");
337
338
217k
    APInt Result(128, 0);
339
217k
    if (StringRef(TokStart, CurPtr - TokStart).getAsInteger(0, Result))
340
0
      return ReturnError(TokStart, "invalid hexadecimal number");
341
342
    // Consume the optional [hH].
343
217k
    if (*CurPtr == 'h' || *CurPtr == 'H')
344
10.4k
      ++CurPtr;
345
346
    // The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL
347
    // suffixes on integer literals.
348
217k
    SkipIgnoredIntegerSuffix(CurPtr);
349
350
217k
    return intToken(StringRef(TokStart, CurPtr - TokStart), Result);
351
217k
  }
352
353
  // Either octal or hexadecimal.
354
3.24M
  APInt Value(128, 0, true);
355
3.24M
  unsigned Radix = doLookAhead(CurPtr, 8);
356
3.24M
  bool isHex = Radix == 16;
357
3.24M
  StringRef Result(TokStart, CurPtr - TokStart);
358
3.24M
  if (Result.getAsInteger(Radix, Value))
359
165k
    return ReturnError(TokStart, !isHex ? "invalid octal number" :
360
165k
                       "invalid hexdecimal number");
361
362
  // Consume the [hH].
363
3.07M
  if (Radix == 16)
364
12.1k
    ++CurPtr;
365
366
  // The darwin/x86 (and x86-64) assembler accepts and ignores ULL and LL
367
  // suffixes on integer literals.
368
3.07M
  SkipIgnoredIntegerSuffix(CurPtr);
369
370
3.07M
  return intToken(Result, Value);
371
3.24M
}
372
373
/// LexSingleQuote: Integer: 'b'
374
AsmToken AsmLexer::LexSingleQuote()
375
504k
{
376
504k
  int CurChar = getNextChar();
377
378
504k
  if (CurChar == '\\')
379
71.1k
    CurChar = getNextChar();
380
381
504k
  if (CurChar == EOF)
382
311
    return ReturnError(TokStart, "unterminated single quote");
383
384
504k
  CurChar = getNextChar();
385
386
504k
  if (CurChar != '\'')
387
409k
    return ReturnError(TokStart, "single quote way too long");
388
389
  // The idea here being that 'c' is basically just an integral
390
  // constant.
391
94.8k
  StringRef Res = StringRef(TokStart,CurPtr - TokStart);
392
94.8k
  long long Value;
393
394
94.8k
  if (Res.startswith("\'\\")) {
395
42.2k
    char theChar = Res[2];
396
42.2k
    switch (theChar) {
397
12.2k
      default: Value = theChar; break;
398
4.49k
      case '\'': Value = '\''; break;
399
7.57k
      case 't': Value = '\t'; break;
400
8.90k
      case 'n': Value = '\n'; break;
401
9.08k
      case 'b': Value = '\b'; break;
402
42.2k
    }
403
42.2k
  } else
404
52.5k
    Value = TokStart[1];
405
406
94.8k
  return AsmToken(AsmToken::Integer, Res, Value);
407
94.8k
}
408
409
410
/// LexQuote: String: "..."
411
AsmToken AsmLexer::LexQuote()
412
1.31M
{
413
1.31M
  int CurChar = getNextChar();
414
  // TODO: does gas allow multiline string constants?
415
8.68M
  while (CurChar != '"') {
416
7.36M
    if (CurChar == '\\') {
417
      // Allow \", etc.
418
217k
      CurChar = getNextChar();
419
217k
    }
420
421
7.36M
    if (CurChar == EOF)
422
1.94k
      return ReturnError(TokStart, "unterminated string constant");
423
424
7.36M
    CurChar = getNextChar();
425
7.36M
  }
426
427
1.31M
  return AsmToken(AsmToken::String, StringRef(TokStart, CurPtr - TokStart));
428
1.31M
}
429
430
32.0k
StringRef AsmLexer::LexUntilEndOfStatement() {
431
32.0k
  TokStart = CurPtr;
432
433
1.75M
  while (!isAtStartOfComment(CurPtr) &&     // Start of line comment.
434
1.75M
         !isAtStatementSeparator(CurPtr) && // End of statement marker.
435
1.74M
         *CurPtr != '\n' && *CurPtr != '\r' &&
436
1.72M
         (*CurPtr != 0 || CurPtr != CurBuf.end())) {
437
1.72M
    ++CurPtr;
438
1.72M
  }
439
32.0k
  return StringRef(TokStart, CurPtr-TokStart);
440
32.0k
}
441
442
1.80M
StringRef AsmLexer::LexUntilEndOfLine() {
443
1.80M
  TokStart = CurPtr;
444
445
16.9M
  while (*CurPtr != '\n' && *CurPtr != '\r' &&
446
15.1M
         (*CurPtr != 0 || CurPtr != CurBuf.end())) {
447
15.1M
    ++CurPtr;
448
15.1M
  }
449
1.80M
  return StringRef(TokStart, CurPtr-TokStart);
450
1.80M
}
451
452
size_t AsmLexer::peekTokens(MutableArrayRef<AsmToken> Buf,
453
                            bool ShouldSkipSpace)
454
272k
{
455
272k
  const char *SavedTokStart = TokStart;
456
272k
  const char *SavedCurPtr = CurPtr;
457
272k
  bool SavedAtStartOfLine = isAtStartOfLine;
458
272k
  bool SavedSkipSpace = SkipSpace;
459
460
272k
  std::string SavedErr = getErr();
461
272k
  SMLoc SavedErrLoc = getErrLoc();
462
463
272k
  SkipSpace = ShouldSkipSpace;
464
465
272k
  size_t ReadCount;
466
548k
  for (ReadCount = 0; ReadCount < Buf.size(); ++ReadCount) {
467
275k
    AsmToken Token = LexToken();
468
469
275k
    Buf[ReadCount] = Token;
470
471
275k
    if (Token.is(AsmToken::Eof))
472
158
      break;
473
275k
  }
474
475
272k
  SetError(SavedErrLoc, SavedErr);
476
477
272k
  SkipSpace = SavedSkipSpace;
478
272k
  isAtStartOfLine = SavedAtStartOfLine;
479
272k
  CurPtr = SavedCurPtr;
480
272k
  TokStart = SavedTokStart;
481
482
272k
  return ReadCount;
483
272k
}
484
485
230M
bool AsmLexer::isAtStartOfComment(const char *Ptr) {
486
230M
  const char *CommentString = MAI.getCommentString();
487
488
230M
  if (CommentString[1] == '\0')
489
212M
    return CommentString[0] == Ptr[0];
490
491
  // FIXME: special case for the bogus "##" comment string in X86MCAsmInfoDarwin
492
18.1M
  if (CommentString[1] == '#')
493
0
    return CommentString[0] == Ptr[0];
494
495
18.1M
  return strncmp(Ptr, CommentString, strlen(CommentString)) == 0;
496
18.1M
}
497
498
229M
bool AsmLexer::isAtStatementSeparator(const char *Ptr) {
499
229M
  return strncmp(Ptr, MAI.getSeparatorString(),
500
229M
                 strlen(MAI.getSeparatorString())) == 0;
501
229M
}
502
503
AsmToken AsmLexer::LexToken()
504
228M
{
505
228M
  TokStart = CurPtr;
506
  // This always consumes at least one character.
507
228M
  int CurChar = getNextChar();
508
509
228M
  if (isAtStartOfComment(TokStart)) {
510
    // If this comment starts with a '#', then return the Hash token and let
511
    // the assembler parser see if it can be parsed as a cpp line filename
512
    // comment. We do this only if we are at the start of a line.
513
1.21M
    if (CurChar == '#' && isAtStartOfLine)
514
696k
      return AsmToken(AsmToken::Hash, StringRef(TokStart, 1));
515
519k
    isAtStartOfLine = true;
516
519k
    return LexLineComment();
517
1.21M
  }
518
227M
  if (isAtStatementSeparator(TokStart)) {
519
60.7M
    CurPtr += strlen(MAI.getSeparatorString()) - 1;
520
60.7M
    return AsmToken(AsmToken::EndOfStatement,
521
60.7M
                    StringRef(TokStart, strlen(MAI.getSeparatorString())));
522
60.7M
  }
523
524
  // If we're missing a newline at EOF, make sure we still get an
525
  // EndOfStatement token before the Eof token.
526
166M
  if (CurChar == EOF && !isAtStartOfLine) {
527
137k
    isAtStartOfLine = true;
528
137k
    return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 1));
529
137k
  }
530
531
166M
  isAtStartOfLine = false;
532
166M
  switch (CurChar) {
533
66.8M
  default:
534
    // Handle identifier: [a-zA-Z_.][a-zA-Z0-9_$.@]*
535
66.8M
    if (isalpha(CurChar) || CurChar == '_' || CurChar == '.')
536
45.3M
      return LexIdentifier();
537
538
    // Unknown character, emit an error.
539
21.4M
    return ReturnError(TokStart, "invalid character in input");
540
135k
  case EOF: return AsmToken(AsmToken::Eof, StringRef(TokStart, 0));
541
0
  case 0:
542
7.47M
  case ' ':
543
9.49M
  case '\t':
544
9.49M
    if (SkipSpace) {
545
      // Ignore whitespace.
546
9.49M
      return LexToken();
547
9.49M
    } else {
548
223
      int len = 1;
549
395
      while (*CurPtr==' ' || *CurPtr=='\t') {
550
172
        CurPtr++;
551
172
        len++;
552
172
      }
553
223
      return AsmToken(AsmToken::Space, StringRef(TokStart, len));
554
223
    }
555
13.3M
  case '\n': // FALL THROUGH.
556
16.6M
  case '\r':
557
16.6M
    isAtStartOfLine = true;
558
16.6M
    return AsmToken(AsmToken::EndOfStatement, StringRef(TokStart, 1));
559
177k
  case ':': return AsmToken(AsmToken::Colon, StringRef(TokStart, 1));
560
2.47M
  case '+': return AsmToken(AsmToken::Plus, StringRef(TokStart, 1));
561
6.14M
  case '-': return AsmToken(AsmToken::Minus, StringRef(TokStart, 1));
562
596k
  case '~': return AsmToken(AsmToken::Tilde, StringRef(TokStart, 1));
563
1.67M
  case '(': return AsmToken(AsmToken::LParen, StringRef(TokStart, 1));
564
788k
  case ')': return AsmToken(AsmToken::RParen, StringRef(TokStart, 1));
565
471k
  case '[': return AsmToken(AsmToken::LBrac, StringRef(TokStart, 1));
566
95.2k
  case ']': return AsmToken(AsmToken::RBrac, StringRef(TokStart, 1));
567
301k
  case '{': return AsmToken(AsmToken::LCurly, StringRef(TokStart, 1));
568
259k
  case '}': return AsmToken(AsmToken::RCurly, StringRef(TokStart, 1));
569
672k
  case '*': return AsmToken(AsmToken::Star, StringRef(TokStart, 1));
570
22.7M
  case ',': return AsmToken(AsmToken::Comma, StringRef(TokStart, 1));
571
6.42M
  case '$': return AsmToken(AsmToken::Dollar, StringRef(TokStart, 1));
572
840k
  case '@': return AsmToken(AsmToken::At, StringRef(TokStart, 1));
573
1.00M
  case '\\': return AsmToken(AsmToken::BackSlash, StringRef(TokStart, 1));
574
4.46M
  case '=':
575
4.46M
    if (*CurPtr == '=')
576
53.5k
      return ++CurPtr, AsmToken(AsmToken::EqualEqual, StringRef(TokStart, 2));
577
4.40M
    return AsmToken(AsmToken::Equal, StringRef(TokStart, 1));
578
1.24M
  case '|':
579
1.24M
    if (*CurPtr == '|')
580
291k
      return ++CurPtr, AsmToken(AsmToken::PipePipe, StringRef(TokStart, 2));
581
950k
    return AsmToken(AsmToken::Pipe, StringRef(TokStart, 1));
582
338k
  case '^': return AsmToken(AsmToken::Caret, StringRef(TokStart, 1));
583
440k
  case '&':
584
440k
    if (*CurPtr == '&')
585
34.1k
      return ++CurPtr, AsmToken(AsmToken::AmpAmp, StringRef(TokStart, 2));
586
406k
    return AsmToken(AsmToken::Amp, StringRef(TokStart, 1));
587
314k
  case '!':
588
314k
    if (*CurPtr == '=')
589
15.4k
      return ++CurPtr, AsmToken(AsmToken::ExclaimEqual, StringRef(TokStart, 2));
590
299k
    return AsmToken(AsmToken::Exclaim, StringRef(TokStart, 1));
591
369k
  case '%': return AsmToken(AsmToken::Percent, StringRef(TokStart, 1));
592
363k
  case '/': return LexSlash();
593
5.22M
  case '#': return AsmToken(AsmToken::Hash, StringRef(TokStart, 1));
594
504k
  case '\'': return LexSingleQuote();
595
1.31M
  case '"': return LexQuote();
596
7.06M
  case '0': case '1': case '2': case '3': case '4':
597
10.6M
  case '5': case '6': case '7': case '8': case '9':
598
10.6M
    return LexDigit();
599
3.16M
  case '<':
600
3.16M
    switch (*CurPtr) {
601
209k
    case '<': return ++CurPtr, AsmToken(AsmToken::LessLess,
602
209k
                                        StringRef(TokStart, 2));
603
17.7k
    case '=': return ++CurPtr, AsmToken(AsmToken::LessEqual,
604
17.7k
                                        StringRef(TokStart, 2));
605
12.0k
    case '>': return ++CurPtr, AsmToken(AsmToken::LessGreater,
606
12.0k
                                        StringRef(TokStart, 2));
607
2.92M
    default: return AsmToken(AsmToken::Less, StringRef(TokStart, 1));
608
3.16M
    }
609
373k
  case '>':
610
373k
    switch (*CurPtr) {
611
49.0k
    case '>': return ++CurPtr, AsmToken(AsmToken::GreaterGreater,
612
49.0k
                                        StringRef(TokStart, 2));
613
39.8k
    case '=': return ++CurPtr, AsmToken(AsmToken::GreaterEqual,
614
39.8k
                                        StringRef(TokStart, 2));
615
285k
    default: return AsmToken(AsmToken::Greater, StringRef(TokStart, 1));
616
373k
    }
617
618
  // TODO: Quoted identifiers (objc methods etc)
619
  // local labels: [0-9][:]
620
  // Forward/backward labels: [0-9][fb]
621
  // Integers, fp constants, character constants.
622
166M
  }
623
166M
}