Coverage Report

Created: 2017-10-03 07:32

/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/AsmParser/LLLexer.cpp
Line
Count
Source (jump to first uncovered line)
1
//===- LLLexer.cpp - Lexer for .ll 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
// Implement the Lexer for .ll files.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#include "LLLexer.h"
15
#include "llvm/ADT/APInt.h"
16
#include "llvm/ADT/STLExtras.h"
17
#include "llvm/ADT/StringExtras.h"
18
#include "llvm/ADT/Twine.h"
19
#include "llvm/IR/DerivedTypes.h"
20
#include "llvm/IR/Instruction.h"
21
#include "llvm/Support/ErrorHandling.h"
22
#include "llvm/Support/SourceMgr.h"
23
#include <cassert>
24
#include <cctype>
25
#include <cstdio>
26
27
using namespace llvm;
28
29
203
bool LLLexer::Error(LocTy ErrorLoc, const Twine &Msg) const {
30
203
  ErrorInfo = SM.GetMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
31
203
  return true;
32
203
}
33
34
0
void LLLexer::Warning(LocTy WarningLoc, const Twine &Msg) const {
35
0
  SM.PrintMessage(WarningLoc, SourceMgr::DK_Warning, Msg);
36
0
}
37
38
//===----------------------------------------------------------------------===//
39
// Helper functions.
40
//===----------------------------------------------------------------------===//
41
42
// atoull - Convert an ascii string of decimal digits into the unsigned long
43
// long representation... this does not have to do input error checking,
44
// because we know that the input will be matched by a suitable regex...
45
//
46
2.95M
uint64_t LLLexer::atoull(const char *Buffer, const char *End) {
47
2.95M
  uint64_t Result = 0;
48
7.91M
  for (; 
Buffer != End7.91M
;
Buffer++4.95M
) {
49
4.95M
    uint64_t OldRes = Result;
50
4.95M
    Result *= 10;
51
4.95M
    Result += *Buffer-'0';
52
4.95M
    if (
Result < OldRes4.95M
) { // Uh, oh, overflow detected!!!
53
0
      Error("constant bigger than 64 bits detected!");
54
0
      return 0;
55
0
    }
56
4.95M
  }
57
2.95M
  return Result;
58
2.95M
}
59
60
6.37k
uint64_t LLLexer::HexIntToVal(const char *Buffer, const char *End) {
61
6.37k
  uint64_t Result = 0;
62
97.0k
  for (; 
Buffer != End97.0k
;
++Buffer90.6k
) {
63
90.6k
    uint64_t OldRes = Result;
64
90.6k
    Result *= 16;
65
90.6k
    Result += hexDigitValue(*Buffer);
66
90.6k
67
90.6k
    if (
Result < OldRes90.6k
) { // Uh, oh, overflow detected!!!
68
1
      Error("constant bigger than 64 bits detected!");
69
1
      return 0;
70
1
    }
71
90.6k
  }
72
6.37k
  return Result;
73
6.37k
}
74
75
void LLLexer::HexToIntPair(const char *Buffer, const char *End,
76
201
                           uint64_t Pair[2]) {
77
201
  Pair[0] = 0;
78
201
  if (
End - Buffer >= 16201
) {
79
3.40k
    for (int i = 0; 
i < 163.40k
;
i++, Buffer++3.20k
) {
80
3.20k
      assert(Buffer != End);
81
3.20k
      Pair[0] *= 16;
82
3.20k
      Pair[0] += hexDigitValue(*Buffer);
83
3.20k
    }
84
200
  }
85
201
  Pair[1] = 0;
86
3.40k
  for (int i = 0; 
i < 16 && 3.40k
Buffer != End3.20k
;
i++, Buffer++3.20k
) {
87
3.20k
    Pair[1] *= 16;
88
3.20k
    Pair[1] += hexDigitValue(*Buffer);
89
3.20k
  }
90
201
  if (Buffer != End)
91
0
    Error("constant bigger than 128 bits detected!");
92
201
}
93
94
/// FP80HexToIntPair - translate an 80 bit FP80 number (20 hexits) into
95
/// { low64, high16 } as usual for an APInt.
96
void LLLexer::FP80HexToIntPair(const char *Buffer, const char *End,
97
136
                           uint64_t Pair[2]) {
98
136
  Pair[1] = 0;
99
677
  for (int i=0; 
i<4 && 677
Buffer != End542
;
i++, Buffer++541
) {
100
541
    assert(Buffer != End);
101
541
    Pair[1] *= 16;
102
541
    Pair[1] += hexDigitValue(*Buffer);
103
541
  }
104
136
  Pair[0] = 0;
105
2.29k
  for (int i = 0; 
i < 16 && 2.29k
Buffer != End2.16k
;
i++, Buffer++2.16k
) {
106
2.16k
    Pair[0] *= 16;
107
2.16k
    Pair[0] += hexDigitValue(*Buffer);
108
2.16k
  }
109
136
  if (Buffer != End)
110
0
    Error("constant bigger than 128 bits detected!");
111
136
}
112
113
// UnEscapeLexed - Run through the specified buffer and change \xx codes to the
114
// appropriate character.
115
160k
static void UnEscapeLexed(std::string &Str) {
116
160k
  if (
Str.empty()160k
)
return4.98k
;
117
155k
118
155k
  char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
119
155k
  char *BOut = Buffer;
120
3.39M
  for (char *BIn = Buffer; 
BIn != EndBuffer3.39M
; ) {
121
3.23M
    if (
BIn[0] == '\\'3.23M
) {
122
7.81k
      if (
BIn < EndBuffer-1 && 7.81k
BIn[1] == '\\'7.81k
) {
123
7
        *BOut++ = '\\'; // Two \ becomes one
124
7
        BIn += 2;
125
7.81k
      } else 
if (7.80k
BIn < EndBuffer-2 &&
126
7.80k
                 isxdigit(static_cast<unsigned char>(BIn[1])) &&
127
7.80k
                 
isxdigit(static_cast<unsigned char>(BIn[2]))7.80k
) {
128
7.80k
        *BOut = hexDigitValue(BIn[1]) * 16 + hexDigitValue(BIn[2]);
129
7.80k
        BIn += 3;                           // Skip over handled chars
130
7.80k
        ++BOut;
131
7.80k
      } else {
132
5
        *BOut++ = *BIn++;
133
5
      }
134
3.23M
    } else {
135
3.22M
      *BOut++ = *BIn++;
136
3.22M
    }
137
3.23M
  }
138
160k
  Str.resize(BOut-Buffer);
139
160k
}
140
141
/// isLabelChar - Return true for [-a-zA-Z$._0-9].
142
31.0M
static bool isLabelChar(char C) {
143
31.0M
  return isalnum(static_cast<unsigned char>(C)) || 
C == '-'9.69M
||
C == '$'9.69M
||
144
31.0M
         
C == '.'9.69M
||
C == '_'9.56M
;
145
31.0M
}
146
147
/// isLabelTail - Return true if this pointer points to a valid end of a label.
148
50.7k
static const char *isLabelTail(const char *CurPtr) {
149
344k
  while (
true344k
) {
150
344k
    if (
CurPtr[0] == ':'344k
)
return CurPtr+1591
;
151
343k
    
if (343k
!isLabelChar(CurPtr[0])343k
)
return nullptr50.1k
;
152
293k
    ++CurPtr;
153
293k
  }
154
50.7k
}
155
156
//===----------------------------------------------------------------------===//
157
// Lexer definition.
158
//===----------------------------------------------------------------------===//
159
160
LLLexer::LLLexer(StringRef StartBuf, SourceMgr &sm, SMDiagnostic &Err,
161
                 LLVMContext &C)
162
27.4k
  : CurBuf(StartBuf), ErrorInfo(Err), SM(sm), Context(C), APFloatVal(0.0) {
163
27.4k
  CurPtr = CurBuf.begin();
164
27.4k
}
165
166
175M
int LLLexer::getNextChar() {
167
175M
  char CurChar = *CurPtr++;
168
175M
  switch (CurChar) {
169
175M
  default: return (unsigned char)CurChar;
170
27.3k
  case 0:
171
27.3k
    // A nul character in the stream is either the end of the current buffer or
172
27.3k
    // a random nul in the file.  Disambiguate that here.
173
27.3k
    if (CurPtr-1 != CurBuf.end())
174
2
      return 0;  // Just whitespace.
175
27.3k
176
27.3k
    // Otherwise, return end of file.
177
27.3k
    --CurPtr;  // Another call to lex will return EOF again.
178
27.3k
    return EOF;
179
175M
  }
180
175M
}
181
182
20.1M
lltok::Kind LLLexer::LexToken() {
183
44.4M
  while (
true44.4M
) {
184
44.4M
    TokStart = CurPtr;
185
44.4M
186
44.4M
    int CurChar = getNextChar();
187
44.4M
    switch (CurChar) {
188
7.13M
    default:
189
7.13M
      // Handle letters: [a-zA-Z_]
190
7.13M
      if (
isalpha(static_cast<unsigned char>(CurChar)) || 7.13M
CurChar == '_'322
)
191
7.13M
        return LexIdentifier();
192
0
193
0
      return lltok::Error;
194
27.3k
    case EOF: return lltok::Eof;
195
21.1M
    case 0:
196
21.1M
    case ' ':
197
21.1M
    case '\t':
198
21.1M
    case '\n':
199
21.1M
    case '\r':
200
21.1M
      // Ignore whitespace.
201
21.1M
      continue;
202
5
    case '+': return LexPositive();
203
431k
    case '@': return LexAt();
204
787
    case '$': return LexDollar();
205
2.41M
    case '%': return LexPercent();
206
91.2k
    case '"': return LexQuote();
207
10.2k
    case '.':
208
10.2k
      if (const char *
Ptr10.2k
= isLabelTail(CurPtr)) {
209
567
        CurPtr = Ptr;
210
567
        StrVal.assign(TokStart, CurPtr-1);
211
567
        return lltok::LabelStr;
212
567
      }
213
9.71k
      
if (9.71k
CurPtr[0] == '.' && 9.71k
CurPtr[1] == '.'9.71k
) {
214
9.71k
        CurPtr += 2;
215
9.71k
        return lltok::dotdotdot;
216
9.71k
      }
217
0
      return lltok::Error;
218
3.15M
    case ';':
219
3.15M
      SkipLineComment();
220
3.15M
      continue;
221
219k
    case '!': return LexExclaim();
222
52.0k
    case '#': return LexHash();
223
2.34M
    
case '0': 2.34M
case '1': 2.34M
case '2': 2.34M
case '3': 2.34M
case '4':
224
2.34M
    
case '5': 2.34M
case '6': 2.34M
case '7': 2.34M
case '8': 2.34M
case '9':
225
2.34M
    case '-':
226
2.34M
      return LexDigitOrNegative();
227
828k
    case '=': return lltok::equal;
228
157k
    case '[': return lltok::lsquare;
229
157k
    case ']': return lltok::rsquare;
230
241k
    case '{': return lltok::lbrace;
231
241k
    case '}': return lltok::rbrace;
232
967k
    case '<': return lltok::less;
233
967k
    case '>': return lltok::greater;
234
518k
    case '(': return lltok::lparen;
235
518k
    case ')': return lltok::rparen;
236
2.20M
    case ',': return lltok::comma;
237
639k
    case '*': return lltok::star;
238
422
    case '|': return lltok::bar;
239
44.4M
    }
240
44.4M
  }
241
20.1M
}
242
243
3.15M
void LLLexer::SkipLineComment() {
244
131M
  while (
true131M
) {
245
131M
    if (
CurPtr[0] == '\n' || 131M
CurPtr[0] == '\r'128M
||
getNextChar() == EOF128M
)
246
3.15M
      return;
247
131M
  }
248
3.15M
}
249
250
/// Lex all tokens that start with an @ character.
251
///   GlobalVar   @\"[^\"]*\"
252
///   GlobalVar   @[-a-zA-Z$._][-a-zA-Z$._0-9]*
253
///   GlobalVarID @[0-9]+
254
431k
lltok::Kind LLLexer::LexAt() {
255
431k
  return LexVar(lltok::GlobalVar, lltok::GlobalID);
256
431k
}
257
258
787
lltok::Kind LLLexer::LexDollar() {
259
787
  if (const char *
Ptr787
= isLabelTail(TokStart)) {
260
0
    CurPtr = Ptr;
261
0
    StrVal.assign(TokStart, CurPtr - 1);
262
0
    return lltok::LabelStr;
263
0
  }
264
787
265
787
  // Handle DollarStringConstant: $\"[^\"]*\"
266
787
  
if (787
CurPtr[0] == '"'787
) {
267
146
    ++CurPtr;
268
146
269
2.60k
    while (
true2.60k
) {
270
2.60k
      int CurChar = getNextChar();
271
2.60k
272
2.60k
      if (
CurChar == EOF2.60k
) {
273
0
        Error("end of file in COMDAT variable name");
274
0
        return lltok::Error;
275
0
      }
276
2.60k
      
if (2.60k
CurChar == '"'2.60k
) {
277
146
        StrVal.assign(TokStart + 2, CurPtr - 1);
278
146
        UnEscapeLexed(StrVal);
279
146
        if (
StringRef(StrVal).find_first_of(0) != StringRef::npos146
) {
280
0
          Error("Null bytes are not allowed in names");
281
0
          return lltok::Error;
282
0
        }
283
146
        return lltok::ComdatVar;
284
146
      }
285
2.60k
    }
286
146
  }
287
787
288
787
  // Handle ComdatVarName: $[-a-zA-Z$._][-a-zA-Z$._0-9]*
289
641
  
if (641
ReadVarName()641
)
290
641
    return lltok::ComdatVar;
291
0
292
0
  return lltok::Error;
293
0
}
294
295
/// ReadString - Read a string until the closing quote.
296
91.2k
lltok::Kind LLLexer::ReadString(lltok::Kind kind) {
297
91.2k
  const char *Start = CurPtr;
298
2.49M
  while (
true2.49M
) {
299
2.49M
    int CurChar = getNextChar();
300
2.49M
301
2.49M
    if (
CurChar == EOF2.49M
) {
302
0
      Error("end of file in string constant");
303
0
      return lltok::Error;
304
0
    }
305
2.49M
    
if (2.49M
CurChar == '"'2.49M
) {
306
91.2k
      StrVal.assign(Start, CurPtr-1);
307
91.2k
      UnEscapeLexed(StrVal);
308
91.2k
      return kind;
309
91.2k
    }
310
2.49M
  }
311
91.2k
}
312
313
/// ReadVarName - Read the rest of a token containing a variable name.
314
2.83M
bool LLLexer::ReadVarName() {
315
2.83M
  const char *NameStart = CurPtr;
316
2.83M
  if (isalpha(static_cast<unsigned char>(CurPtr[0])) ||
317
2.83M
      
CurPtr[0] == '-'476k
||
CurPtr[0] == '$'476k
||
318
2.83M
      
CurPtr[0] == '.'476k
||
CurPtr[0] == '_'466k
) {
319
2.44M
    ++CurPtr;
320
15.1M
    while (isalnum(static_cast<unsigned char>(CurPtr[0])) ||
321
15.1M
           
CurPtr[0] == '-'3.84M
||
CurPtr[0] == '$'3.84M
||
322
15.1M
           
CurPtr[0] == '.'3.84M
||
CurPtr[0] == '_'3.02M
)
323
12.6M
      ++CurPtr;
324
2.44M
325
2.44M
    StrVal.assign(NameStart, CurPtr);
326
2.44M
    return true;
327
2.44M
  }
328
387k
  return false;
329
387k
}
330
331
2.84M
lltok::Kind LLLexer::LexVar(lltok::Kind Var, lltok::Kind VarID) {
332
2.84M
  // Handle StringConstant: \"[^\"]*\"
333
2.84M
  if (
CurPtr[0] == '"'2.84M
) {
334
9.92k
    ++CurPtr;
335
9.92k
336
303k
    while (
true303k
) {
337
303k
      int CurChar = getNextChar();
338
303k
339
303k
      if (
CurChar == EOF303k
) {
340
0
        Error("end of file in global variable name");
341
0
        return lltok::Error;
342
0
      }
343
303k
      
if (303k
CurChar == '"'303k
) {
344
9.92k
        StrVal.assign(TokStart+2, CurPtr-1);
345
9.92k
        UnEscapeLexed(StrVal);
346
9.92k
        if (
StringRef(StrVal).find_first_of(0) != StringRef::npos9.92k
) {
347
1
          Error("Null bytes are not allowed in names");
348
1
          return lltok::Error;
349
1
        }
350
9.92k
        return Var;
351
9.92k
      }
352
303k
    }
353
9.92k
  }
354
2.84M
355
2.84M
  // Handle VarName: [-a-zA-Z$._][-a-zA-Z$._0-9]*
356
2.83M
  
if (2.83M
ReadVarName()2.83M
)
357
2.44M
    return Var;
358
387k
359
387k
  // Handle VarID: [0-9]+
360
387k
  
if (387k
isdigit(static_cast<unsigned char>(CurPtr[0]))387k
) {
361
464k
    for (++CurPtr; 
isdigit(static_cast<unsigned char>(CurPtr[0]))464k
;
++CurPtr76.4k
)
362
76.4k
      /*empty*/;
363
387k
364
387k
    uint64_t Val = atoull(TokStart+1, CurPtr);
365
387k
    if ((unsigned)Val != Val)
366
0
      Error("invalid value number (too large)!");
367
387k
    UIntVal = unsigned(Val);
368
387k
    return VarID;
369
387k
  }
370
0
  return lltok::Error;
371
0
}
372
373
/// Lex all tokens that start with a % character.
374
///   LocalVar   ::= %\"[^\"]*\"
375
///   LocalVar   ::= %[-a-zA-Z$._][-a-zA-Z$._0-9]*
376
///   LocalVarID ::= %[0-9]+
377
2.41M
lltok::Kind LLLexer::LexPercent() {
378
2.41M
  return LexVar(lltok::LocalVar, lltok::LocalVarID);
379
2.41M
}
380
381
/// Lex all tokens that start with a " character.
382
///   QuoteLabel        "[^"]+":
383
///   StringConstant    "[^"]*"
384
91.2k
lltok::Kind LLLexer::LexQuote() {
385
91.2k
  lltok::Kind kind = ReadString(lltok::StringConstant);
386
91.2k
  if (
kind == lltok::Error || 91.2k
kind == lltok::Eof91.2k
)
387
0
    return kind;
388
91.2k
389
91.2k
  
if (91.2k
CurPtr[0] == ':'91.2k
) {
390
529
    ++CurPtr;
391
529
    if (
StringRef(StrVal).find_first_of(0) != StringRef::npos529
) {
392
1
      Error("Null bytes are not allowed in names");
393
1
      kind = lltok::Error;
394
529
    } else {
395
528
      kind = lltok::LabelStr;
396
528
    }
397
529
  }
398
91.2k
399
91.2k
  return kind;
400
91.2k
}
401
402
/// Lex all tokens that start with a ! character.
403
///    !foo
404
///    !
405
219k
lltok::Kind LLLexer::LexExclaim() {
406
219k
  // Lex a metadata name as a MetadataVar.
407
219k
  if (isalpha(static_cast<unsigned char>(CurPtr[0])) ||
408
219k
      
CurPtr[0] == '-'160k
||
CurPtr[0] == '$'160k
||
409
219k
      
CurPtr[0] == '.'160k
||
CurPtr[0] == '_'160k
||
CurPtr[0] == '\\'160k
) {
410
58.9k
    ++CurPtr;
411
551k
    while (isalnum(static_cast<unsigned char>(CurPtr[0])) ||
412
551k
           
CurPtr[0] == '-'70.3k
||
CurPtr[0] == '$'70.3k
||
413
551k
           
CurPtr[0] == '.'70.3k
||
CurPtr[0] == '_'62.3k
||
CurPtr[0] == '\\'58.9k
)
414
492k
      ++CurPtr;
415
58.9k
416
58.9k
    StrVal.assign(TokStart+1, CurPtr);   // Skip !
417
58.9k
    UnEscapeLexed(StrVal);
418
58.9k
    return lltok::MetadataVar;
419
58.9k
  }
420
160k
  return lltok::exclaim;
421
160k
}
422
423
/// Lex all tokens that start with a # character.
424
///    AttrGrpID ::= #[0-9]+
425
52.0k
lltok::Kind LLLexer::LexHash() {
426
52.0k
  // Handle AttrGrpID: #[0-9]+
427
52.0k
  if (
isdigit(static_cast<unsigned char>(CurPtr[0]))52.0k
) {
428
52.4k
    for (++CurPtr; 
isdigit(static_cast<unsigned char>(CurPtr[0]))52.4k
;
++CurPtr409
)
429
409
      /*empty*/;
430
52.0k
431
52.0k
    uint64_t Val = atoull(TokStart+1, CurPtr);
432
52.0k
    if ((unsigned)Val != Val)
433
0
      Error("invalid value number (too large)!");
434
52.0k
    UIntVal = unsigned(Val);
435
52.0k
    return lltok::AttrGrpID;
436
52.0k
  }
437
0
438
0
  return lltok::Error;
439
0
}
440
441
/// Lex a label, integer type, keyword, or hexadecimal integer constant.
442
///    Label           [-a-zA-Z$._0-9]+:
443
///    IntegerType     i[0-9]+
444
///    Keyword         sdiv, float, ...
445
///    HexIntConstant  [us]0x[0-9A-Fa-f]+
446
7.13M
lltok::Kind LLLexer::LexIdentifier() {
447
7.13M
  const char *StartChar = CurPtr;
448
7.13M
  const char *IntEnd = CurPtr[-1] == 'i' ? 
nullptr2.69M
:
StartChar4.43M
;
449
7.13M
  const char *KeywordEnd = nullptr;
450
7.13M
451
28.3M
  for (; 
isLabelChar(*CurPtr)28.3M
;
++CurPtr21.2M
) {
452
21.2M
    // If we decide this is an integer, remember the end of the sequence.
453
21.2M
    if (
!IntEnd && 21.2M
!isdigit(static_cast<unsigned char>(*CurPtr))4.62M
)
454
182k
      IntEnd = CurPtr;
455
21.2M
    if (
!KeywordEnd && 21.2M
!isalnum(static_cast<unsigned char>(*CurPtr))21.0M
&&
456
103k
        *CurPtr != '_')
457
33.5k
      KeywordEnd = CurPtr;
458
21.2M
  }
459
7.13M
460
7.13M
  // If we stopped due to a colon, this really is a label.
461
7.13M
  if (
*CurPtr == ':'7.13M
) {
462
239k
    StrVal.assign(StartChar-1, CurPtr++);
463
239k
    return lltok::LabelStr;
464
239k
  }
465
6.89M
466
6.89M
  // Otherwise, this wasn't a label.  If this was valid as an integer type,
467
6.89M
  // return it.
468
6.89M
  
if (6.89M
!IntEnd6.89M
)
IntEnd = CurPtr2.51M
;
469
6.89M
  if (
IntEnd != StartChar6.89M
) {
470
2.51M
    CurPtr = IntEnd;
471
2.51M
    uint64_t NumBits = atoull(StartChar, CurPtr);
472
2.51M
    if (NumBits < IntegerType::MIN_INT_BITS ||
473
2.51M
        
NumBits > IntegerType::MAX_INT_BITS2.51M
) {
474
1
      Error("bitwidth for integer type out of range!");
475
1
      return lltok::Error;
476
1
    }
477
2.51M
    TyVal = IntegerType::get(Context, NumBits);
478
2.51M
    return lltok::Type;
479
2.51M
  }
480
4.37M
481
4.37M
  // Otherwise, this was a letter sequence.  See which keyword this is.
482
4.37M
  
if (4.37M
!KeywordEnd4.37M
)
KeywordEnd = CurPtr4.37M
;
483
4.37M
  CurPtr = KeywordEnd;
484
4.37M
  --StartChar;
485
4.37M
  StringRef Keyword(StartChar, CurPtr - StartChar);
486
4.37M
487
4.37M
#define KEYWORD(STR)                                                           \
488
733M
  
do 733M
{ \
489
733M
    if (Keyword == #STR)                                                       \
490
2.30M
      return lltok::kw_##STR;                                                  \
491
733M
  } while (false)
492
4.37M
493
4.37M
  
KEYWORD4.37M
(true);
KEYWORD4.36M
(false);
494
4.34M
  
KEYWORD4.34M
(declare); 4.34M
KEYWORD4.29M
(define);
495
4.11M
  
KEYWORD4.11M
(global); 4.11M
KEYWORD4.09M
(constant);
496
4.09M
497
4.08M
  
KEYWORD4.08M
(private);
498
4.08M
  
KEYWORD4.08M
(internal);
499
4.08M
  
KEYWORD4.08M
(available_externally);
500
4.08M
  
KEYWORD4.08M
(linkonce);
501
4.08M
  
KEYWORD4.08M
(linkonce_odr);
502
4.08M
  
KEYWORD4.08M
(weak); // Use as a linkage, and a modifier for "cmpxchg".
503
4.08M
  
KEYWORD4.08M
(weak_odr);
504
4.08M
  
KEYWORD4.08M
(appending);
505
4.08M
  
KEYWORD4.08M
(dllimport);
506
4.08M
  
KEYWORD4.08M
(dllexport);
507
4.08M
  
KEYWORD4.08M
(common);
508
4.07M
  
KEYWORD4.07M
(default);
509
4.07M
  
KEYWORD4.07M
(hidden);
510
4.07M
  
KEYWORD4.07M
(protected);
511
4.07M
  
KEYWORD4.07M
(unnamed_addr);
512
4.07M
  
KEYWORD4.07M
(local_unnamed_addr);
513
4.07M
  
KEYWORD4.07M
(externally_initialized);
514
4.07M
  
KEYWORD4.07M
(extern_weak);
515
4.07M
  
KEYWORD4.07M
(external);
516
4.06M
  
KEYWORD4.06M
(thread_local);
517
4.06M
  
KEYWORD4.06M
(localdynamic);
518
4.06M
  
KEYWORD4.06M
(initialexec);
519
4.06M
  
KEYWORD4.06M
(localexec);
520
4.06M
  
KEYWORD4.06M
(zeroinitializer);
521
4.04M
  
KEYWORD4.04M
(undef);
522
3.97M
  
KEYWORD3.97M
(null);
523
3.96M
  
KEYWORD3.96M
(none);
524
3.96M
  
KEYWORD3.96M
(to);
525
3.86M
  
KEYWORD3.86M
(caller);
526
3.86M
  
KEYWORD3.86M
(within);
527
3.86M
  
KEYWORD3.86M
(from);
528
3.86M
  
KEYWORD3.86M
(tail);
529
3.83M
  
KEYWORD3.83M
(musttail);
530
3.83M
  
KEYWORD3.83M
(notail);
531
3.83M
  
KEYWORD3.83M
(target);
532
3.82M
  
KEYWORD3.82M
(triple);
533
3.82M
  
KEYWORD3.82M
(source_filename);
534
3.81M
  
KEYWORD3.81M
(unwind);
535
3.81M
  
KEYWORD3.81M
(deplibs); // FIXME: Remove in 4.0.
536
3.81M
  
KEYWORD3.81M
(datalayout);
537
3.81M
  
KEYWORD3.81M
(volatile);
538
3.79M
  
KEYWORD3.79M
(atomic);
539
3.78M
  
KEYWORD3.78M
(unordered);
540
3.78M
  
KEYWORD3.78M
(monotonic);
541
3.78M
  
KEYWORD3.78M
(acquire);
542
3.78M
  
KEYWORD3.78M
(release);
543
3.78M
  
KEYWORD3.78M
(acq_rel);
544
3.78M
  
KEYWORD3.78M
(seq_cst);
545
3.78M
  
KEYWORD3.78M
(syncscope);
546
3.78M
547
3.77M
  
KEYWORD3.77M
(nnan);
548
3.77M
  
KEYWORD3.77M
(ninf);
549
3.77M
  
KEYWORD3.77M
(nsz);
550
3.77M
  
KEYWORD3.77M
(arcp);
551
3.77M
  
KEYWORD3.77M
(contract);
552
3.77M
  
KEYWORD3.77M
(fast);
553
3.77M
  
KEYWORD3.77M
(nuw);
554
3.77M
  
KEYWORD3.77M
(nsw);
555
3.75M
  
KEYWORD3.75M
(exact);
556
3.75M
  
KEYWORD3.75M
(inbounds);
557
3.66M
  
KEYWORD3.66M
(inrange);
558
3.66M
  
KEYWORD3.66M
(align);
559
3.44M
  
KEYWORD3.44M
(addrspace);
560
3.36M
  
KEYWORD3.36M
(section);
561
3.36M
  
KEYWORD3.36M
(alias);
562
3.36M
  
KEYWORD3.36M
(ifunc);
563
3.36M
  
KEYWORD3.36M
(module);
564
3.36M
  
KEYWORD3.36M
(asm);
565
3.35M
  
KEYWORD3.35M
(sideeffect);
566
3.34M
  
KEYWORD3.34M
(alignstack);
567
3.34M
  
KEYWORD3.34M
(inteldialect);
568
3.34M
  
KEYWORD3.34M
(gc);
569
3.34M
  
KEYWORD3.34M
(prefix);
570
3.34M
  
KEYWORD3.34M
(prologue);
571
3.34M
572
3.34M
  
KEYWORD3.34M
(ccc);
573
3.34M
  
KEYWORD3.34M
(fastcc);
574
3.34M
  
KEYWORD3.34M
(coldcc);
575
3.34M
  
KEYWORD3.34M
(x86_stdcallcc);
576
3.34M
  
KEYWORD3.34M
(x86_fastcallcc);
577
3.34M
  
KEYWORD3.34M
(x86_thiscallcc);
578
3.34M
  
KEYWORD3.34M
(x86_vectorcallcc);
579
3.34M
  
KEYWORD3.34M
(arm_apcscc);
580
3.34M
  
KEYWORD3.34M
(arm_aapcscc);
581
3.34M
  
KEYWORD3.34M
(arm_aapcs_vfpcc);
582
3.34M
  
KEYWORD3.34M
(msp430_intrcc);
583
3.34M
  
KEYWORD3.34M
(avr_intrcc);
584
3.34M
  
KEYWORD3.34M
(avr_signalcc);
585
3.34M
  
KEYWORD3.34M
(ptx_kernel);
586
3.34M
  
KEYWORD3.34M
(ptx_device);
587
3.34M
  
KEYWORD3.34M
(spir_kernel);
588
3.34M
  
KEYWORD3.34M
(spir_func);
589
3.34M
  
KEYWORD3.34M
(intel_ocl_bicc);
590
3.34M
  
KEYWORD3.34M
(x86_64_sysvcc);
591
3.34M
  
KEYWORD3.34M
(win64cc);
592
3.34M
  
KEYWORD3.34M
(x86_regcallcc);
593
3.34M
  
KEYWORD3.34M
(webkit_jscc);
594
3.34M
  
KEYWORD3.34M
(swiftcc);
595
3.34M
  
KEYWORD3.34M
(anyregcc);
596
3.34M
  
KEYWORD3.34M
(preserve_mostcc);
597
3.34M
  
KEYWORD3.34M
(preserve_allcc);
598
3.34M
  
KEYWORD3.34M
(ghccc);
599
3.34M
  
KEYWORD3.34M
(x86_intrcc);
600
3.34M
  
KEYWORD3.34M
(hhvmcc);
601
3.33M
  
KEYWORD3.33M
(hhvm_ccc);
602
3.33M
  
KEYWORD3.33M
(cxx_fast_tlscc);
603
3.33M
  
KEYWORD3.33M
(amdgpu_vs);
604
3.33M
  
KEYWORD3.33M
(amdgpu_hs);
605
3.33M
  
KEYWORD3.33M
(amdgpu_gs);
606
3.33M
  
KEYWORD3.33M
(amdgpu_ps);
607
3.33M
  
KEYWORD3.33M
(amdgpu_cs);
608
3.33M
  
KEYWORD3.33M
(amdgpu_kernel);
609
3.33M
610
3.32M
  
KEYWORD3.32M
(cc);
611
3.32M
  
KEYWORD3.32M
(c);
612
3.32M
613
3.32M
  
KEYWORD3.32M
(attributes);
614
3.32M
615
3.31M
  
KEYWORD3.31M
(alwaysinline);
616
3.31M
  
KEYWORD3.31M
(allocsize);
617
3.31M
  
KEYWORD3.31M
(argmemonly);
618
3.31M
  
KEYWORD3.31M
(builtin);
619
3.31M
  
KEYWORD3.31M
(byval);
620
3.31M
  
KEYWORD3.31M
(inalloca);
621
3.31M
  
KEYWORD3.31M
(cold);
622
3.31M
  
KEYWORD3.31M
(convergent);
623
3.31M
  
KEYWORD3.31M
(dereferenceable);
624
3.31M
  
KEYWORD3.31M
(dereferenceable_or_null);
625
3.31M
  
KEYWORD3.31M
(inaccessiblememonly);
626
3.31M
  
KEYWORD3.31M
(inaccessiblemem_or_argmemonly);
627
3.31M
  
KEYWORD3.31M
(inlinehint);
628
3.31M
  
KEYWORD3.31M
(inreg);
629
3.30M
  
KEYWORD3.30M
(jumptable);
630
3.30M
  
KEYWORD3.30M
(minsize);
631
3.30M
  
KEYWORD3.30M
(naked);
632
3.30M
  
KEYWORD3.30M
(nest);
633
3.30M
  
KEYWORD3.30M
(noalias);
634
3.30M
  
KEYWORD3.30M
(nobuiltin);
635
3.30M
  
KEYWORD3.30M
(nocapture);
636
3.29M
  
KEYWORD3.29M
(noduplicate);
637
3.29M
  
KEYWORD3.29M
(noimplicitfloat);
638
3.29M
  
KEYWORD3.29M
(noinline);
639
3.29M
  
KEYWORD3.29M
(norecurse);
640
3.29M
  
KEYWORD3.29M
(nonlazybind);
641
3.29M
  
KEYWORD3.29M
(nonnull);
642
3.29M
  
KEYWORD3.29M
(noredzone);
643
3.29M
  
KEYWORD3.29M
(noreturn);
644
3.29M
  
KEYWORD3.29M
(nounwind);
645
3.22M
  
KEYWORD3.22M
(optnone);
646
3.22M
  
KEYWORD3.22M
(optsize);
647
3.22M
  
KEYWORD3.22M
(readnone);
648
3.20M
  
KEYWORD3.20M
(readonly);
649
3.20M
  
KEYWORD3.20M
(returned);
650
3.20M
  
KEYWORD3.20M
(returns_twice);
651
3.20M
  
KEYWORD3.20M
(signext);
652
3.18M
  
KEYWORD3.18M
(speculatable);
653
3.18M
  
KEYWORD3.18M
(sret);
654
3.18M
  
KEYWORD3.18M
(ssp);
655
3.18M
  
KEYWORD3.18M
(sspreq);
656
3.18M
  
KEYWORD3.18M
(sspstrong);
657
3.18M
  
KEYWORD3.18M
(strictfp);
658
3.18M
  
KEYWORD3.18M
(safestack);
659
3.18M
  
KEYWORD3.18M
(sanitize_address);
660
3.18M
  
KEYWORD3.18M
(sanitize_thread);
661
3.18M
  
KEYWORD3.18M
(sanitize_memory);
662
3.18M
  
KEYWORD3.18M
(swifterror);
663
3.18M
  
KEYWORD3.18M
(swiftself);
664
3.18M
  
KEYWORD3.18M
(uwtable);
665
3.17M
  
KEYWORD3.17M
(writeonly);
666
3.17M
  
KEYWORD3.17M
(zeroext);
667
3.17M
668
3.16M
  
KEYWORD3.16M
(type);
669
3.15M
  
KEYWORD3.15M
(opaque);
670
3.15M
671
3.15M
  
KEYWORD3.15M
(comdat);
672
3.15M
673
3.15M
  // Comdat types
674
3.15M
  
KEYWORD3.15M
(any);
675
3.15M
  
KEYWORD3.15M
(exactmatch);
676
3.15M
  
KEYWORD3.15M
(largest);
677
3.15M
  
KEYWORD3.15M
(noduplicates);
678
3.15M
  
KEYWORD3.15M
(samesize);
679
3.15M
680
3.15M
  
KEYWORD3.15M
(eq); 3.15M
KEYWORD3.14M
(ne); 3.14M
KEYWORD3.13M
(slt); 3.13M
KEYWORD3.13M
(sgt); 3.13M
KEYWORD3.12M
(sle);
681
3.12M
  
KEYWORD3.12M
(sge); 3.12M
KEYWORD3.12M
(ult); 3.12M
KEYWORD3.12M
(ugt); 3.12M
KEYWORD3.11M
(ule); 3.11M
KEYWORD3.11M
(uge);
682
3.11M
  
KEYWORD3.11M
(oeq); 3.11M
KEYWORD3.11M
(one); 3.11M
KEYWORD3.11M
(olt); 3.11M
KEYWORD3.11M
(ogt); 3.11M
KEYWORD3.11M
(ole);
683
3.11M
  
KEYWORD3.11M
(oge); 3.11M
KEYWORD3.11M
(ord); 3.11M
KEYWORD3.11M
(uno); 3.11M
KEYWORD3.10M
(ueq); 3.10M
KEYWORD3.10M
(une);
684
3.10M
685
3.10M
  
KEYWORD3.10M
(xchg); 3.10M
KEYWORD3.10M
(nand); 3.10M
KEYWORD3.10M
(max); 3.10M
KEYWORD3.10M
(min); 3.10M
KEYWORD3.10M
(umax);
686
3.10M
  
KEYWORD3.10M
(umin);
687
3.10M
688
3.10M
  
KEYWORD3.10M
(x);
689
2.07M
  
KEYWORD2.07M
(blockaddress);
690
2.07M
691
2.07M
  // Metadata types.
692
2.07M
  
KEYWORD2.07M
(distinct);
693
2.07M
694
2.07M
  // Use-list order directives.
695
2.07M
  
KEYWORD2.07M
(uselistorder);
696
2.06M
  
KEYWORD2.06M
(uselistorder_bb);
697
2.06M
698
2.06M
  
KEYWORD2.06M
(personality);
699
2.06M
  
KEYWORD2.06M
(cleanup);
700
2.06M
  
KEYWORD2.06M
(catch);
701
2.06M
  
KEYWORD2.06M
(filter);
702
2.06M
703
2.06M
#undef KEYWORD
704
2.06M
705
2.06M
  // Keywords for types.
706
2.06M
#define TYPEKEYWORD(STR, LLVMTY)                                               \
707
16.0M
  
do 16.0M
{ \
708
16.0M
    if (
Keyword == STR16.0M
) { \
709
895k
      TyVal = LLVMTY;                                                          \
710
895k
      return lltok::Type;                                                      \
711
895k
    }                                                                          \
712
16.0M
  } while (false)
713
2.06M
714
2.06M
  
TYPEKEYWORD2.06M
("void", Type::getVoidTy(Context));
715
1.89M
  
TYPEKEYWORD1.89M
("half", Type::getHalfTy(Context));
716
1.86M
  
TYPEKEYWORD1.86M
("float", Type::getFloatTy(Context));
717
1.47M
  
TYPEKEYWORD1.47M
("double", Type::getDoubleTy(Context));
718
1.29M
  
TYPEKEYWORD1.29M
("x86_fp80", Type::getX86_FP80Ty(Context));
719
1.29M
  
TYPEKEYWORD1.29M
("fp128", Type::getFP128Ty(Context));
720
1.28M
  
TYPEKEYWORD1.28M
("ppc_fp128", Type::getPPC_FP128Ty(Context));
721
1.28M
  
TYPEKEYWORD1.28M
("label", Type::getLabelTy(Context));
722
1.18M
  
TYPEKEYWORD1.18M
("metadata", Type::getMetadataTy(Context));
723
1.17M
  
TYPEKEYWORD1.17M
("x86_mmx", Type::getX86_MMXTy(Context));
724
1.17M
  
TYPEKEYWORD1.17M
("token", Type::getTokenTy(Context));
725
1.17M
726
1.17M
#undef TYPEKEYWORD
727
1.17M
728
1.17M
  // Keywords for instructions.
729
1.17M
#define INSTKEYWORD(STR, Enum)                                                 \
730
41.9M
  
do 41.9M
{ \
731
41.9M
    if (
Keyword == #41.9M
STR) { \
732
1.16M
      UIntVal = Instruction::Enum;                                             \
733
1.16M
      return lltok::kw_##STR;                                                  \
734
1.16M
    }                                                                          \
735
41.9M
  } while (false)
736
1.17M
737
1.17M
  
INSTKEYWORD1.17M
(add, Add); 1.17M
INSTKEYWORD1.13M
(fadd, FAdd);
738
1.12M
  
INSTKEYWORD1.12M
(sub, Sub); 1.12M
INSTKEYWORD1.11M
(fsub, FSub);
739
1.10M
  
INSTKEYWORD1.10M
(mul, Mul); 1.10M
INSTKEYWORD1.09M
(fmul, FMul);
740
1.09M
  
INSTKEYWORD1.09M
(udiv, UDiv); 1.09M
INSTKEYWORD1.08M
(sdiv, SDiv); 1.08M
INSTKEYWORD1.08M
(fdiv, FDiv);
741
1.08M
  
INSTKEYWORD1.08M
(urem, URem); 1.08M
INSTKEYWORD1.08M
(srem, SRem); 1.08M
INSTKEYWORD1.08M
(frem, FRem);
742
1.08M
  
INSTKEYWORD1.08M
(shl, Shl); 1.08M
INSTKEYWORD1.07M
(lshr, LShr); 1.07M
INSTKEYWORD1.06M
(ashr, AShr);
743
1.06M
  
INSTKEYWORD1.06M
(and, And); 1.06M
INSTKEYWORD1.05M
(or, Or); 1.05M
INSTKEYWORD1.04M
(xor, Xor);
744
1.03M
  
INSTKEYWORD1.03M
(icmp, ICmp); 1.03M
INSTKEYWORD996k
(fcmp, FCmp);
745
996k
746
988k
  
INSTKEYWORD988k
(phi, PHI);
747
970k
  
INSTKEYWORD970k
(call, Call);
748
862k
  
INSTKEYWORD862k
(trunc, Trunc);
749
854k
  
INSTKEYWORD854k
(zext, ZExt);
750
842k
  
INSTKEYWORD842k
(sext, SExt);
751
829k
  
INSTKEYWORD829k
(fptrunc, FPTrunc);
752
828k
  
INSTKEYWORD828k
(fpext, FPExt);
753
826k
  
INSTKEYWORD826k
(uitofp, UIToFP);
754
823k
  
INSTKEYWORD823k
(sitofp, SIToFP);
755
819k
  
INSTKEYWORD819k
(fptoui, FPToUI);
756
818k
  
INSTKEYWORD818k
(fptosi, FPToSI);
757
815k
  
INSTKEYWORD815k
(inttoptr, IntToPtr);
758
813k
  
INSTKEYWORD813k
(ptrtoint, PtrToInt);
759
811k
  
INSTKEYWORD811k
(bitcast, BitCast);
760
762k
  
INSTKEYWORD762k
(addrspacecast, AddrSpaceCast);
761
761k
  
INSTKEYWORD761k
(select, Select);
762
744k
  
INSTKEYWORD744k
(va_arg, VAArg);
763
744k
  
INSTKEYWORD744k
(ret, Ret);
764
557k
  
INSTKEYWORD557k
(br, Br);
765
497k
  
INSTKEYWORD497k
(switch, Switch);
766
495k
  
INSTKEYWORD495k
(indirectbr, IndirectBr);
767
495k
  
INSTKEYWORD495k
(invoke, Invoke);
768
493k
  
INSTKEYWORD493k
(resume, Resume);
769
493k
  
INSTKEYWORD493k
(unreachable, Unreachable);
770
493k
771
490k
  
INSTKEYWORD490k
(alloca, Alloca);
772
446k
  
INSTKEYWORD446k
(load, Load);
773
310k
  
INSTKEYWORD310k
(store, Store);
774
202k
  
INSTKEYWORD202k
(cmpxchg, AtomicCmpXchg);
775
201k
  
INSTKEYWORD201k
(atomicrmw, AtomicRMW);
776
196k
  
INSTKEYWORD196k
(fence, Fence);
777
195k
  
INSTKEYWORD195k
(getelementptr, GetElementPtr);
778
195k
779
82.7k
  
INSTKEYWORD82.7k
(extractelement, ExtractElement);
780
68.9k
  
INSTKEYWORD68.9k
(insertelement, InsertElement);
781
45.5k
  
INSTKEYWORD45.5k
(shufflevector, ShuffleVector);
782
17.4k
  
INSTKEYWORD17.4k
(extractvalue, ExtractValue);
783
13.3k
  
INSTKEYWORD13.3k
(insertvalue, InsertValue);
784
12.0k
  
INSTKEYWORD12.0k
(landingpad, LandingPad);
785
11.0k
  
INSTKEYWORD11.0k
(cleanupret, CleanupRet);
786
10.9k
  
INSTKEYWORD10.9k
(catchret, CatchRet);
787
10.7k
  
INSTKEYWORD10.7k
(catchswitch, CatchSwitch);
788
10.4k
  
INSTKEYWORD10.4k
(catchpad, CatchPad);
789
10.2k
  
INSTKEYWORD10.2k
(cleanuppad, CleanupPad);
790
10.2k
791
10.2k
#undef INSTKEYWORD
792
10.2k
793
10.2k
#define DWKEYWORD(TYPE, TOKEN)                                                 \
794
41.8k
  
do 41.8k
{ \
795
41.8k
    if (
Keyword.startswith("DW_" #TYPE "_")41.8k
) { \
796
5.92k
      StrVal.assign(Keyword.begin(), Keyword.end());                           \
797
5.92k
      return lltok::TOKEN;                                                     \
798
5.92k
    }                                                                          \
799
41.8k
  } while (false)
800
10.2k
801
9.99k
  
DWKEYWORD9.99k
(TAG, DwarfTag);
802
7.03k
  
DWKEYWORD7.03k
(ATE, DwarfAttEncoding);
803
5.93k
  
DWKEYWORD5.93k
(VIRTUALITY, DwarfVirtuality);
804
5.88k
  
DWKEYWORD5.88k
(LANG, DwarfLang);
805
4.47k
  
DWKEYWORD4.47k
(CC, DwarfCC);
806
4.42k
  
DWKEYWORD4.42k
(OP, DwarfOp);
807
4.09k
  
DWKEYWORD4.09k
(MACINFO, DwarfMacinfo);
808
4.09k
809
4.09k
#undef DWKEYWORD
810
4.09k
811
4.07k
  
if (4.07k
Keyword.startswith("DIFlag")4.07k
) {
812
2.63k
    StrVal.assign(Keyword.begin(), Keyword.end());
813
2.63k
    return lltok::DIFlag;
814
2.63k
  }
815
1.44k
816
1.44k
  
if (1.44k
Keyword.startswith("CSK_")1.44k
) {
817
63
    StrVal.assign(Keyword.begin(), Keyword.end());
818
63
    return lltok::ChecksumKind;
819
63
  }
820
1.38k
821
1.38k
  
if (1.38k
Keyword == "NoDebug" || 1.38k
Keyword == "FullDebug"1.26k
||
822
1.38k
      
Keyword == "LineTablesOnly"253
) {
823
1.26k
    StrVal.assign(Keyword.begin(), Keyword.end());
824
1.26k
    return lltok::EmissionKind;
825
1.26k
  }
826
112
827
112
  // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
828
112
  // the CFE to avoid forcing it to deal with 64-bit numbers.
829
112
  
if (112
(TokStart[0] == 'u' || 112
TokStart[0] == 's'90
) &&
830
112
      
TokStart[1] == '0'24
&&
TokStart[2] == 'x'24
&&
831
112
      
isxdigit(static_cast<unsigned char>(TokStart[3]))24
) {
832
24
    int len = CurPtr-TokStart-3;
833
24
    uint32_t bits = len * 4;
834
24
    StringRef HexStr(TokStart + 3, len);
835
24
    if (
!all_of(HexStr, isxdigit)24
) {
836
1
      // Bad token, return it as an error.
837
1
      CurPtr = TokStart+3;
838
1
      return lltok::Error;
839
1
    }
840
23
    APInt Tmp(bits, HexStr, 16);
841
23
    uint32_t activeBits = Tmp.getActiveBits();
842
23
    if (
activeBits > 0 && 23
activeBits < bits23
)
843
22
      Tmp = Tmp.trunc(activeBits);
844
24
    APSIntVal = APSInt(Tmp, TokStart[0] == 'u');
845
24
    return lltok::APSInt;
846
24
  }
847
88
848
88
  // If this is "cc1234", return this as just "cc".
849
88
  
if (88
TokStart[0] == 'c' && 88
TokStart[1] == 'c'82
) {
850
82
    CurPtr = TokStart+2;
851
82
    return lltok::kw_cc;
852
82
  }
853
6
854
6
  // Finally, if this isn't known, return an error.
855
6
  CurPtr = TokStart+1;
856
6
  return lltok::Error;
857
6
}
858
859
/// Lex all tokens that start with a 0x prefix, knowing they match and are not
860
/// labels.
861
///    HexFPConstant     0x[0-9A-Fa-f]+
862
///    HexFP80Constant   0xK[0-9A-Fa-f]+
863
///    HexFP128Constant  0xL[0-9A-Fa-f]+
864
///    HexPPC128Constant 0xM[0-9A-Fa-f]+
865
///    HexHalfConstant   0xH[0-9A-Fa-f]+
866
6.71k
lltok::Kind LLLexer::Lex0x() {
867
6.71k
  CurPtr = TokStart + 2;
868
6.71k
869
6.71k
  char Kind;
870
6.71k
  if (
(CurPtr[0] >= 'K' && 6.71k
CurPtr[0] <= 'M'1.04k
) ||
CurPtr[0] == 'H'6.37k
) {
871
672
    Kind = *CurPtr++;
872
6.71k
  } else {
873
6.04k
    Kind = 'J';
874
6.04k
  }
875
6.71k
876
6.71k
  if (
!isxdigit(static_cast<unsigned char>(CurPtr[0]))6.71k
) {
877
0
    // Bad token, return it as an error.
878
0
    CurPtr = TokStart+1;
879
0
    return lltok::Error;
880
0
  }
881
6.71k
882
106k
  
while (6.71k
isxdigit(static_cast<unsigned char>(CurPtr[0]))106k
)
883
99.7k
    ++CurPtr;
884
6.71k
885
6.71k
  if (
Kind == 'J'6.71k
) {
886
6.04k
    // HexFPConstant - Floating point constant represented in IEEE format as a
887
6.04k
    // hexadecimal number for when exponential notation is not precise enough.
888
6.04k
    // Half, Float, and double only.
889
6.04k
    APFloatVal = APFloat(APFloat::IEEEdouble(),
890
6.04k
                         APInt(64, HexIntToVal(TokStart + 2, CurPtr)));
891
6.04k
    return lltok::APFloat;
892
6.04k
  }
893
672
894
672
  uint64_t Pair[2];
895
672
  switch (Kind) {
896
0
  
default: 0
llvm_unreachable0
("Unknown kind!");
897
136
  case 'K':
898
136
    // F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
899
136
    FP80HexToIntPair(TokStart+3, CurPtr, Pair);
900
136
    APFloatVal = APFloat(APFloat::x87DoubleExtended(), APInt(80, Pair));
901
136
    return lltok::APFloat;
902
134
  case 'L':
903
134
    // F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
904
134
    HexToIntPair(TokStart+3, CurPtr, Pair);
905
134
    APFloatVal = APFloat(APFloat::IEEEquad(), APInt(128, Pair));
906
134
    return lltok::APFloat;
907
67
  case 'M':
908
67
    // PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
909
67
    HexToIntPair(TokStart+3, CurPtr, Pair);
910
67
    APFloatVal = APFloat(APFloat::PPCDoubleDouble(), APInt(128, Pair));
911
67
    return lltok::APFloat;
912
335
  case 'H':
913
335
    APFloatVal = APFloat(APFloat::IEEEhalf(),
914
335
                         APInt(16,HexIntToVal(TokStart+3, CurPtr)));
915
335
    return lltok::APFloat;
916
0
  }
917
0
}
918
919
/// Lex tokens for a label or a numeric constant, possibly starting with -.
920
///    Label             [-a-zA-Z$._0-9]+:
921
///    NInteger          -[0-9]+
922
///    FPConstant        [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
923
///    PInteger          [0-9]+
924
///    HexFPConstant     0x[0-9A-Fa-f]+
925
///    HexFP80Constant   0xK[0-9A-Fa-f]+
926
///    HexFP128Constant  0xL[0-9A-Fa-f]+
927
///    HexPPC128Constant 0xM[0-9A-Fa-f]+
928
2.34M
lltok::Kind LLLexer::LexDigitOrNegative() {
929
2.34M
  // If the letter after the negative is not a number, this is probably a label.
930
2.34M
  if (!isdigit(static_cast<unsigned char>(TokStart[0])) &&
931
2.34M
      
!isdigit(static_cast<unsigned char>(CurPtr[0]))43.8k
) {
932
0
    // Okay, this is not a number after the -, it's probably a label.
933
0
    if (const char *
End0
= isLabelTail(CurPtr)) {
934
0
      StrVal.assign(TokStart, End-1);
935
0
      CurPtr = End;
936
0
      return lltok::LabelStr;
937
0
    }
938
0
939
0
    return lltok::Error;
940
0
  }
941
2.34M
942
2.34M
  // At this point, it is either a label, int or fp constant.
943
2.34M
944
2.34M
  // Skip digits, we have at least one.
945
3.19M
  
for (; 2.34M
isdigit(static_cast<unsigned char>(CurPtr[0]))3.19M
;
++CurPtr848k
)
946
848k
    /*empty*/;
947
2.34M
948
2.34M
  // Check to see if this really is a label afterall, e.g. "-1:".
949
2.34M
  if (
isLabelChar(CurPtr[0]) || 2.34M
CurPtr[0] == ':'2.30M
) {
950
39.6k
    if (const char *
End39.6k
= isLabelTail(CurPtr)) {
951
24
      StrVal.assign(TokStart, End-1);
952
24
      CurPtr = End;
953
24
      return lltok::LabelStr;
954
24
    }
955
2.34M
  }
956
2.34M
957
2.34M
  // If the next character is a '.', then it is a fp value, otherwise its
958
2.34M
  // integer.
959
2.34M
  
if (2.34M
CurPtr[0] != '.'2.34M
) {
960
2.31M
    if (
TokStart[0] == '0' && 2.31M
TokStart[1] == 'x'219k
)
961
6.71k
      return Lex0x();
962
2.30M
    APSIntVal = APSInt(StringRef(TokStart, CurPtr - TokStart));
963
2.30M
    return lltok::APSInt;
964
2.30M
  }
965
32.7k
966
32.7k
  ++CurPtr;
967
32.7k
968
32.7k
  // Skip over [0-9]*([eE][-+]?[0-9]+)?
969
140k
  while (
isdigit(static_cast<unsigned char>(CurPtr[0]))140k
)
++CurPtr107k
;
970
32.7k
971
32.7k
  if (
CurPtr[0] == 'e' || 32.7k
CurPtr[0] == 'E'17.6k
) {
972
15.0k
    if (isdigit(static_cast<unsigned char>(CurPtr[1])) ||
973
14.9k
        
((CurPtr[1] == '-' || 14.9k
CurPtr[1] == '+'14.6k
) &&
974
15.0k
          
isdigit(static_cast<unsigned char>(CurPtr[2]))14.9k
)) {
975
15.0k
      CurPtr += 2;
976
45.1k
      while (
isdigit(static_cast<unsigned char>(CurPtr[0]))45.1k
)
++CurPtr30.0k
;
977
15.0k
    }
978
15.0k
  }
979
2.34M
980
2.34M
  APFloatVal = APFloat(APFloat::IEEEdouble(),
981
2.34M
                       StringRef(TokStart, CurPtr - TokStart));
982
2.34M
  return lltok::APFloat;
983
2.34M
}
984
985
/// Lex a floating point constant starting with +.
986
///    FPConstant  [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
987
5
lltok::Kind LLLexer::LexPositive() {
988
5
  // If the letter after the negative is a number, this is probably not a
989
5
  // label.
990
5
  if (!isdigit(static_cast<unsigned char>(CurPtr[0])))
991
0
    return lltok::Error;
992
5
993
5
  // Skip digits.
994
5
  
for (++CurPtr; 5
isdigit(static_cast<unsigned char>(CurPtr[0]))5
;
++CurPtr0
)
995
0
    /*empty*/;
996
5
997
5
  // At this point, we need a '.'.
998
5
  if (
CurPtr[0] != '.'5
) {
999
0
    CurPtr = TokStart+1;
1000
0
    return lltok::Error;
1001
0
  }
1002
5
1003
5
  ++CurPtr;
1004
5
1005
5
  // Skip over [0-9]*([eE][-+]?[0-9]+)?
1006
10
  while (
isdigit(static_cast<unsigned char>(CurPtr[0]))10
)
++CurPtr5
;
1007
5
1008
5
  if (
CurPtr[0] == 'e' || 5
CurPtr[0] == 'E'5
) {
1009
0
    if (isdigit(static_cast<unsigned char>(CurPtr[1])) ||
1010
0
        
((CurPtr[1] == '-' || 0
CurPtr[1] == '+'0
) &&
1011
0
        
isdigit(static_cast<unsigned char>(CurPtr[2]))0
)) {
1012
0
      CurPtr += 2;
1013
0
      while (
isdigit(static_cast<unsigned char>(CurPtr[0]))0
)
++CurPtr0
;
1014
0
    }
1015
0
  }
1016
5
1017
5
  APFloatVal = APFloat(APFloat::IEEEdouble(),
1018
5
                       StringRef(TokStart, CurPtr - TokStart));
1019
5
  return lltok::APFloat;
1020
5
}