LLVM 23.0.0git
LLLexer.cpp
Go to the documentation of this file.
1//===- LLLexer.cpp - Lexer for .ll Files ----------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Implement the Lexer for .ll files.
10//
11//===----------------------------------------------------------------------===//
12
14#include "llvm/ADT/APInt.h"
15#include "llvm/ADT/STLExtras.h"
17#include "llvm/ADT/Twine.h"
19#include "llvm/IR/Instruction.h"
22#include <cassert>
23#include <cctype>
24#include <cstdio>
25
26using namespace llvm;
27
28// Both the lexer and parser can issue error messages. If the lexer issues a
29// lexer error, since we do not terminate execution immediately, usually that
30// is followed by the parser issuing a parser error. However, the error issued
31// by the lexer is more relevant in that case as opposed to potentially more
32// generic parser error. So instead of always recording the last error message
33// use the `Priority` to establish a priority, with Lexer > Parser > None. We
34// record the issued message only if the message has same or higher priority
35// than the existing one. This prevents lexer errors from being overwritten by
36// parser errors.
37void LLLexer::Error(LocTy ErrorLoc, const Twine &Msg,
38 LLLexer::ErrorPriority Priority) {
39 if (Priority < ErrorInfo.Priority)
40 return;
41 ErrorInfo.Error = SM.GetMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
42 ErrorInfo.Priority = Priority;
43}
44
45void LLLexer::Warning(LocTy WarningLoc, const Twine &Msg) const {
46 SM.PrintMessage(WarningLoc, SourceMgr::DK_Warning, Msg);
47}
48
49//===----------------------------------------------------------------------===//
50// Helper functions.
51//===----------------------------------------------------------------------===//
52
53// atoull - Convert an ascii string of decimal digits into the unsigned long
54// long representation... this does not have to do input error checking,
55// because we know that the input will be matched by a suitable regex...
56//
57uint64_t LLLexer::atoull(const char *Buffer, const char *End) {
58 uint64_t Result = 0;
59 for (; Buffer != End; Buffer++) {
60 uint64_t OldRes = Result;
61 Result *= 10;
62 Result += *Buffer-'0';
63 if (Result < OldRes) { // overflow detected.
64 LexError("constant bigger than 64 bits detected");
65 return 0;
66 }
67 }
68 return Result;
69}
70
71uint64_t LLLexer::HexIntToVal(const char *Buffer, const char *End) {
72 uint64_t Result = 0;
73 for (; Buffer != End; ++Buffer) {
74 uint64_t OldRes = Result;
75 Result *= 16;
76 Result += hexDigitValue(*Buffer);
77
78 if (Result < OldRes) { // overflow detected.
79 LexError("constant bigger than 64 bits detected");
80 return 0;
81 }
82 }
83 return Result;
84}
85
86void LLLexer::HexToIntPair(const char *Buffer, const char *End,
87 uint64_t Pair[2]) {
88 Pair[0] = 0;
89 if (End - Buffer >= 16) {
90 for (int i = 0; i < 16; i++, Buffer++) {
91 assert(Buffer != End);
92 Pair[0] *= 16;
93 Pair[0] += hexDigitValue(*Buffer);
94 }
95 }
96 Pair[1] = 0;
97 for (int i = 0; i < 16 && Buffer != End; i++, Buffer++) {
98 Pair[1] *= 16;
99 Pair[1] += hexDigitValue(*Buffer);
100 }
101 if (Buffer != End)
102 LexError("constant bigger than 128 bits detected");
103}
104
105/// FP80HexToIntPair - translate an 80 bit FP80 number (20 hexits) into
106/// { low64, high16 } as usual for an APInt.
107void LLLexer::FP80HexToIntPair(const char *Buffer, const char *End,
108 uint64_t Pair[2]) {
109 Pair[1] = 0;
110 for (int i=0; i<4 && Buffer != End; i++, Buffer++) {
111 assert(Buffer != End);
112 Pair[1] *= 16;
113 Pair[1] += hexDigitValue(*Buffer);
114 }
115 Pair[0] = 0;
116 for (int i = 0; i < 16 && Buffer != End; i++, Buffer++) {
117 Pair[0] *= 16;
118 Pair[0] += hexDigitValue(*Buffer);
119 }
120 if (Buffer != End)
121 LexError("constant bigger than 128 bits detected");
122}
123
124// UnEscapeLexed - Run through the specified buffer and change \xx codes to the
125// appropriate character.
126static void UnEscapeLexed(std::string &Str) {
127 if (Str.empty()) return;
128
129 char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
130 char *BOut = Buffer;
131 for (char *BIn = Buffer; BIn != EndBuffer; ) {
132 if (BIn[0] == '\\') {
133 if (BIn < EndBuffer-1 && BIn[1] == '\\') {
134 *BOut++ = '\\'; // Two \ becomes one
135 BIn += 2;
136 } else if (BIn < EndBuffer-2 &&
137 isxdigit(static_cast<unsigned char>(BIn[1])) &&
138 isxdigit(static_cast<unsigned char>(BIn[2]))) {
139 *BOut = hexDigitValue(BIn[1]) * 16 + hexDigitValue(BIn[2]);
140 BIn += 3; // Skip over handled chars
141 ++BOut;
142 } else {
143 *BOut++ = *BIn++;
144 }
145 } else {
146 *BOut++ = *BIn++;
147 }
148 }
149 Str.resize(BOut-Buffer);
150}
151
152/// isLabelChar - Return true for [-a-zA-Z$._0-9].
153static bool isLabelChar(char C) {
154 return isalnum(static_cast<unsigned char>(C)) || C == '-' || C == '$' ||
155 C == '.' || C == '_';
156}
157
158/// isLabelTail - Return true if this pointer points to a valid end of a label.
159static const char *isLabelTail(const char *CurPtr) {
160 while (true) {
161 if (CurPtr[0] == ':') return CurPtr+1;
162 if (!isLabelChar(CurPtr[0])) return nullptr;
163 ++CurPtr;
164 }
165}
166
167//===----------------------------------------------------------------------===//
168// Lexer definition.
169//===----------------------------------------------------------------------===//
170
172 LLVMContext &C)
173 : CurBuf(StartBuf), ErrorInfo(Err), SM(SM), Context(C) {
174 CurPtr = CurBuf.begin();
175}
176
177int LLLexer::getNextChar() {
178 char CurChar = *CurPtr++;
179 switch (CurChar) {
180 default: return (unsigned char)CurChar;
181 case 0:
182 // A nul character in the stream is either the end of the current buffer or
183 // a random nul in the file. Disambiguate that here.
184 if (CurPtr-1 != CurBuf.end())
185 return 0; // Just whitespace.
186
187 // Otherwise, return end of file.
188 --CurPtr; // Another call to lex will return EOF again.
189 return EOF;
190 }
191}
192
193lltok::Kind LLLexer::LexToken() {
194 // Set token end to next location, since the end is exclusive.
195 PrevTokEnd = CurPtr;
196 while (true) {
197 TokStart = CurPtr;
198
199 int CurChar = getNextChar();
200 switch (CurChar) {
201 default:
202 // Handle letters: [a-zA-Z_]
203 if (isalpha(static_cast<unsigned char>(CurChar)) || CurChar == '_')
204 return LexIdentifier();
205 return lltok::Error;
206 case EOF: return lltok::Eof;
207 case 0:
208 case ' ':
209 case '\t':
210 case '\n':
211 case '\r':
212 // Ignore whitespace.
213 continue;
214 case '+': return LexPositive();
215 case '@': return LexAt();
216 case '$': return LexDollar();
217 case '%': return LexPercent();
218 case '"': return LexQuote();
219 case '.':
220 if (const char *Ptr = isLabelTail(CurPtr)) {
221 CurPtr = Ptr;
222 StrVal.assign(TokStart, CurPtr-1);
223 return lltok::LabelStr;
224 }
225 if (CurPtr[0] == '.' && CurPtr[1] == '.') {
226 CurPtr += 2;
227 return lltok::dotdotdot;
228 }
229 return lltok::Error;
230 case ';':
231 SkipLineComment();
232 continue;
233 case '!': return LexExclaim();
234 case '^':
235 return LexCaret();
236 case ':':
237 return lltok::colon;
238 case '#': return LexHash();
239 case '0': case '1': case '2': case '3': case '4':
240 case '5': case '6': case '7': case '8': case '9':
241 case '-':
242 return LexDigitOrNegative();
243 case '=': return lltok::equal;
244 case '[': return lltok::lsquare;
245 case ']': return lltok::rsquare;
246 case '{': return lltok::lbrace;
247 case '}': return lltok::rbrace;
248 case '<': return lltok::less;
249 case '>': return lltok::greater;
250 case '(': return lltok::lparen;
251 case ')': return lltok::rparen;
252 case ',': return lltok::comma;
253 case '*': return lltok::star;
254 case '|': return lltok::bar;
255 case '/':
256 if (getNextChar() != '*')
257 return lltok::Error;
258 if (SkipCComment())
259 return lltok::Error;
260 continue;
261 }
262 }
263}
264
265void LLLexer::SkipLineComment() {
266 while (true) {
267 if (CurPtr[0] == '\n' || CurPtr[0] == '\r' || getNextChar() == EOF)
268 return;
269 }
270}
271
272/// This skips C-style /**/ comments. Returns true if there
273/// was an error.
274bool LLLexer::SkipCComment() {
275 while (true) {
276 int CurChar = getNextChar();
277 switch (CurChar) {
278 case EOF:
279 LexError("unterminated comment");
280 return true;
281 case '*':
282 // End of the comment?
283 CurChar = getNextChar();
284 if (CurChar == '/')
285 return false;
286 if (CurChar == EOF) {
287 LexError("unterminated comment");
288 return true;
289 }
290 }
291 }
292}
293
294/// Lex all tokens that start with an @ character.
295/// GlobalVar @\"[^\"]*\"
296/// GlobalVar @[-a-zA-Z$._][-a-zA-Z$._0-9]*
297/// GlobalVarID @[0-9]+
298lltok::Kind LLLexer::LexAt() {
299 return LexVar(lltok::GlobalVar, lltok::GlobalID);
300}
301
302lltok::Kind LLLexer::LexDollar() {
303 if (const char *Ptr = isLabelTail(TokStart)) {
304 CurPtr = Ptr;
305 StrVal.assign(TokStart, CurPtr - 1);
306 return lltok::LabelStr;
307 }
308
309 // Handle DollarStringConstant: $\"[^\"]*\"
310 if (CurPtr[0] == '"') {
311 ++CurPtr;
312
313 while (true) {
314 int CurChar = getNextChar();
315
316 if (CurChar == EOF) {
317 LexError("end of file in COMDAT variable name");
318 return lltok::Error;
319 }
320 if (CurChar == '"') {
321 StrVal.assign(TokStart + 2, CurPtr - 1);
322 UnEscapeLexed(StrVal);
323 if (StringRef(StrVal).contains(0)) {
324 LexError("NUL character is not allowed in names");
325 return lltok::Error;
326 }
327 return lltok::ComdatVar;
328 }
329 }
330 }
331
332 // Handle ComdatVarName: $[-a-zA-Z$._][-a-zA-Z$._0-9]*
333 if (ReadVarName())
334 return lltok::ComdatVar;
335
336 return lltok::Error;
337}
338
339/// ReadString - Read a string until the closing quote.
340lltok::Kind LLLexer::ReadString(lltok::Kind kind) {
341 const char *Start = CurPtr;
342 while (true) {
343 int CurChar = getNextChar();
344
345 if (CurChar == EOF) {
346 LexError("end of file in string constant");
347 return lltok::Error;
348 }
349 if (CurChar == '"') {
350 StrVal.assign(Start, CurPtr-1);
351 UnEscapeLexed(StrVal);
352 return kind;
353 }
354 }
355}
356
357/// ReadVarName - Read the rest of a token containing a variable name.
358bool LLLexer::ReadVarName() {
359 const char *NameStart = CurPtr;
360 if (isalpha(static_cast<unsigned char>(CurPtr[0])) ||
361 CurPtr[0] == '-' || CurPtr[0] == '$' ||
362 CurPtr[0] == '.' || CurPtr[0] == '_') {
363 ++CurPtr;
364 while (isalnum(static_cast<unsigned char>(CurPtr[0])) ||
365 CurPtr[0] == '-' || CurPtr[0] == '$' ||
366 CurPtr[0] == '.' || CurPtr[0] == '_')
367 ++CurPtr;
368
369 StrVal.assign(NameStart, CurPtr);
370 return true;
371 }
372 return false;
373}
374
375// Lex an ID: [0-9]+. On success, the ID is stored in UIntVal and Token is
376// returned, otherwise the Error token is returned.
377lltok::Kind LLLexer::LexUIntID(lltok::Kind Token) {
378 if (!isdigit(static_cast<unsigned char>(CurPtr[0])))
379 return lltok::Error;
380
381 for (++CurPtr; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
382 /*empty*/;
383
384 uint64_t Val = atoull(TokStart + 1, CurPtr);
385 if ((unsigned)Val != Val)
386 LexError("invalid value number (too large)");
387 UIntVal = unsigned(Val);
388 return Token;
389}
390
391lltok::Kind LLLexer::LexVar(lltok::Kind Var, lltok::Kind VarID) {
392 // Handle StringConstant: \"[^\"]*\"
393 if (CurPtr[0] == '"') {
394 ++CurPtr;
395
396 while (true) {
397 int CurChar = getNextChar();
398
399 if (CurChar == EOF) {
400 LexError("end of file in global variable name");
401 return lltok::Error;
402 }
403 if (CurChar == '"') {
404 StrVal.assign(TokStart+2, CurPtr-1);
405 UnEscapeLexed(StrVal);
406 if (StringRef(StrVal).contains(0)) {
407 LexError("NUL character is not allowed in names");
408 return lltok::Error;
409 }
410 return Var;
411 }
412 }
413 }
414
415 // Handle VarName: [-a-zA-Z$._][-a-zA-Z$._0-9]*
416 if (ReadVarName())
417 return Var;
418
419 // Handle VarID: [0-9]+
420 return LexUIntID(VarID);
421}
422
423/// Lex all tokens that start with a % character.
424/// LocalVar ::= %\"[^\"]*\"
425/// LocalVar ::= %[-a-zA-Z$._][-a-zA-Z$._0-9]*
426/// LocalVarID ::= %[0-9]+
427lltok::Kind LLLexer::LexPercent() {
428 return LexVar(lltok::LocalVar, lltok::LocalVarID);
429}
430
431/// Lex all tokens that start with a " character.
432/// QuoteLabel "[^"]+":
433/// StringConstant "[^"]*"
434lltok::Kind LLLexer::LexQuote() {
435 lltok::Kind kind = ReadString(lltok::StringConstant);
436 if (kind == lltok::Error || kind == lltok::Eof)
437 return kind;
438
439 if (CurPtr[0] == ':') {
440 ++CurPtr;
441 if (StringRef(StrVal).contains(0)) {
442 LexError("NUL character is not allowed in names");
443 kind = lltok::Error;
444 } else {
445 kind = lltok::LabelStr;
446 }
447 }
448
449 return kind;
450}
451
452/// Lex all tokens that start with a ! character.
453/// !foo
454/// !
455lltok::Kind LLLexer::LexExclaim() {
456 // Lex a metadata name as a MetadataVar.
457 if (isalpha(static_cast<unsigned char>(CurPtr[0])) ||
458 CurPtr[0] == '-' || CurPtr[0] == '$' ||
459 CurPtr[0] == '.' || CurPtr[0] == '_' || CurPtr[0] == '\\') {
460 ++CurPtr;
461 while (isalnum(static_cast<unsigned char>(CurPtr[0])) ||
462 CurPtr[0] == '-' || CurPtr[0] == '$' ||
463 CurPtr[0] == '.' || CurPtr[0] == '_' || CurPtr[0] == '\\')
464 ++CurPtr;
465
466 StrVal.assign(TokStart+1, CurPtr); // Skip !
467 UnEscapeLexed(StrVal);
468 return lltok::MetadataVar;
469 }
470 return lltok::exclaim;
471}
472
473/// Lex all tokens that start with a ^ character.
474/// SummaryID ::= ^[0-9]+
475lltok::Kind LLLexer::LexCaret() {
476 // Handle SummaryID: ^[0-9]+
477 return LexUIntID(lltok::SummaryID);
478}
479
480/// Lex all tokens that start with a # character.
481/// AttrGrpID ::= #[0-9]+
482/// Hash ::= #
483lltok::Kind LLLexer::LexHash() {
484 // Handle AttrGrpID: #[0-9]+
485 if (isdigit(static_cast<unsigned char>(CurPtr[0])))
486 return LexUIntID(lltok::AttrGrpID);
487 return lltok::hash;
488}
489
490/// Lex a label, integer or byte types, keyword, or hexadecimal integer
491/// constant.
492/// Label [-a-zA-Z$._0-9]+:
493/// ByteType b[0-9]+
494/// IntegerType i[0-9]+
495/// Keyword sdiv, float, ...
496/// HexIntConstant [us]0x[0-9A-Fa-f]+
497lltok::Kind LLLexer::LexIdentifier() {
498 const char *StartChar = CurPtr;
499 const char IntOrByteIdentifier = CurPtr[-1];
500 const char *IntOrByteEnd =
501 (IntOrByteIdentifier == 'i' || IntOrByteIdentifier == 'b') ? nullptr
502 : StartChar;
503 const char *KeywordEnd = nullptr;
504
505 for (; isLabelChar(*CurPtr); ++CurPtr) {
506 // If we decide this is a byte or an integer, remember the end of the
507 // sequence.
508 if (!IntOrByteEnd && !isdigit(static_cast<unsigned char>(*CurPtr)))
509 IntOrByteEnd = CurPtr;
510 if (!KeywordEnd && !isalnum(static_cast<unsigned char>(*CurPtr)) &&
511 *CurPtr != '_')
512 KeywordEnd = CurPtr;
513 }
514
515 // If we stopped due to a colon, unless we were directed to ignore it,
516 // this really is a label.
517 if (!IgnoreColonInIdentifiers && *CurPtr == ':') {
518 StrVal.assign(StartChar-1, CurPtr++);
519 return lltok::LabelStr;
520 }
521
522 // Otherwise, this wasn't a label. If this was valid as a byte or an integer
523 // type, return it.
524 if (!IntOrByteEnd)
525 IntOrByteEnd = CurPtr;
526 if (IntOrByteEnd != StartChar) {
527 CurPtr = IntOrByteEnd;
528 uint64_t NumBits = atoull(StartChar, CurPtr);
529 if (NumBits < IntegerType::MIN_INT_BITS ||
530 NumBits > IntegerType::MAX_INT_BITS) {
531 LexError("bitwidth for integer or byte type out of range");
532 return lltok::Error;
533 }
534 if (IntOrByteIdentifier == 'i')
535 TyVal = IntegerType::get(Context, NumBits);
536 else
537 TyVal = ByteType::get(Context, NumBits);
538
539 return lltok::Type;
540 }
541
542 // Otherwise, this was a letter sequence. See which keyword this is.
543 if (!KeywordEnd) KeywordEnd = CurPtr;
544 CurPtr = KeywordEnd;
545 --StartChar;
546 StringRef Keyword(StartChar, CurPtr - StartChar);
547
548#define KEYWORD(STR) \
549 do { \
550 if (Keyword == #STR) \
551 return lltok::kw_##STR; \
552 } while (false)
553
554 KEYWORD(true); KEYWORD(false);
555 KEYWORD(declare); KEYWORD(define);
556 KEYWORD(global); KEYWORD(constant);
557 KEYWORD(br);
558
559 KEYWORD(dso_local);
560 KEYWORD(dso_preemptable);
561
562 KEYWORD(private);
563 KEYWORD(internal);
564 KEYWORD(available_externally);
565 KEYWORD(linkonce);
566 KEYWORD(linkonce_odr);
567 KEYWORD(weak); // Use as a linkage, and a modifier for "cmpxchg".
568 KEYWORD(weak_odr);
569 KEYWORD(appending);
570 KEYWORD(dllimport);
571 KEYWORD(dllexport);
572 KEYWORD(common);
573 KEYWORD(default);
574 KEYWORD(hidden);
575 KEYWORD(protected);
576 KEYWORD(unnamed_addr);
577 KEYWORD(local_unnamed_addr);
578 KEYWORD(externally_initialized);
579 KEYWORD(extern_weak);
580 KEYWORD(external);
581 KEYWORD(thread_local);
582 KEYWORD(localdynamic);
583 KEYWORD(initialexec);
584 KEYWORD(localexec);
585 KEYWORD(zeroinitializer);
586 KEYWORD(undef);
587 KEYWORD(null);
588 KEYWORD(none);
589 KEYWORD(poison);
590 KEYWORD(to);
591 KEYWORD(caller);
592 KEYWORD(within);
593 KEYWORD(from);
594 KEYWORD(tail);
595 KEYWORD(musttail);
596 KEYWORD(notail);
597 KEYWORD(target);
598 KEYWORD(triple);
599 KEYWORD(source_filename);
600 KEYWORD(unwind);
601 KEYWORD(datalayout);
602 KEYWORD(volatile);
603 KEYWORD(atomic);
604 KEYWORD(unordered);
605 KEYWORD(monotonic);
610 KEYWORD(syncscope);
611
612 KEYWORD(nnan);
613 KEYWORD(ninf);
614 KEYWORD(nsz);
615 KEYWORD(arcp);
617 KEYWORD(reassoc);
618 KEYWORD(afn);
619 KEYWORD(fast);
620 KEYWORD(nuw);
621 KEYWORD(nsw);
622 KEYWORD(nusw);
623 KEYWORD(exact);
624 KEYWORD(disjoint);
625 KEYWORD(inbounds);
626 KEYWORD(nneg);
627 KEYWORD(samesign);
628 KEYWORD(inrange);
629 KEYWORD(addrspace);
630 KEYWORD(section);
632 KEYWORD(code_model);
633 KEYWORD(alias);
634 KEYWORD(ifunc);
635 KEYWORD(module);
636 KEYWORD(asm);
637 KEYWORD(sideeffect);
638 KEYWORD(inteldialect);
639 KEYWORD(gc);
640 KEYWORD(prefix);
641 KEYWORD(prologue);
642 KEYWORD(prefalign);
643
644 KEYWORD(no_sanitize_address);
645 KEYWORD(no_sanitize_hwaddress);
646 KEYWORD(sanitize_address_dyninit);
647
648 KEYWORD(ccc);
649 KEYWORD(fastcc);
650 KEYWORD(coldcc);
651 KEYWORD(cfguard_checkcc);
652 KEYWORD(x86_stdcallcc);
653 KEYWORD(x86_fastcallcc);
654 KEYWORD(x86_thiscallcc);
655 KEYWORD(x86_vectorcallcc);
656 KEYWORD(arm_apcscc);
657 KEYWORD(arm_aapcscc);
658 KEYWORD(arm_aapcs_vfpcc);
659 KEYWORD(aarch64_vector_pcs);
660 KEYWORD(aarch64_sve_vector_pcs);
661 KEYWORD(aarch64_sme_preservemost_from_x0);
662 KEYWORD(aarch64_sme_preservemost_from_x1);
663 KEYWORD(aarch64_sme_preservemost_from_x2);
664 KEYWORD(msp430_intrcc);
665 KEYWORD(avr_intrcc);
666 KEYWORD(avr_signalcc);
667 KEYWORD(ptx_kernel);
668 KEYWORD(ptx_device);
669 KEYWORD(spir_kernel);
670 KEYWORD(spir_func);
671 KEYWORD(intel_ocl_bicc);
672 KEYWORD(x86_64_sysvcc);
673 KEYWORD(win64cc);
674 KEYWORD(x86_regcallcc);
675 KEYWORD(swiftcc);
676 KEYWORD(swifttailcc);
677 KEYWORD(anyregcc);
678 KEYWORD(preserve_mostcc);
679 KEYWORD(preserve_allcc);
680 KEYWORD(preserve_nonecc);
681 KEYWORD(ghccc);
682 KEYWORD(x86_intrcc);
683 KEYWORD(hhvmcc);
684 KEYWORD(hhvm_ccc);
685 KEYWORD(cxx_fast_tlscc);
686 KEYWORD(amdgpu_vs);
687 KEYWORD(amdgpu_ls);
688 KEYWORD(amdgpu_hs);
689 KEYWORD(amdgpu_es);
690 KEYWORD(amdgpu_gs);
691 KEYWORD(amdgpu_ps);
692 KEYWORD(amdgpu_cs);
693 KEYWORD(amdgpu_cs_chain);
694 KEYWORD(amdgpu_cs_chain_preserve);
695 KEYWORD(amdgpu_kernel);
696 KEYWORD(amdgpu_gfx);
697 KEYWORD(amdgpu_gfx_whole_wave);
698 KEYWORD(tailcc);
699 KEYWORD(m68k_rtdcc);
700 KEYWORD(graalcc);
701 KEYWORD(riscv_vector_cc);
702 KEYWORD(riscv_vls_cc);
703 KEYWORD(cheriot_compartmentcallcc);
704 KEYWORD(cheriot_compartmentcalleecc);
705 KEYWORD(cheriot_librarycallcc);
706
707 KEYWORD(cc);
708 KEYWORD(c);
709
710 KEYWORD(attributes);
711 KEYWORD(sync);
712 KEYWORD(async);
713
714#define GET_ATTR_NAMES
715#define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
716 KEYWORD(DISPLAY_NAME);
717#include "llvm/IR/Attributes.inc"
718
719 KEYWORD(read);
720 KEYWORD(write);
721 KEYWORD(readwrite);
722 KEYWORD(argmem);
723 KEYWORD(target_mem0);
724 KEYWORD(target_mem1);
725 KEYWORD(target_mem);
726 KEYWORD(inaccessiblemem);
727 KEYWORD(errnomem);
728 KEYWORD(argmemonly);
729 KEYWORD(inaccessiblememonly);
730 KEYWORD(inaccessiblemem_or_argmemonly);
731 KEYWORD(nocapture);
732 KEYWORD(address_is_null);
733 KEYWORD(address);
734 KEYWORD(provenance);
735 KEYWORD(read_provenance);
736
737 // denormal_fpenv attribute
738 KEYWORD(ieee);
739 KEYWORD(preservesign);
740 KEYWORD(positivezero);
741 KEYWORD(dynamic);
742
743 // nofpclass attribute
744 KEYWORD(all);
745 KEYWORD(nan);
746 KEYWORD(snan);
747 KEYWORD(qnan);
748 KEYWORD(inf);
749 // ninf already a keyword
750 KEYWORD(pinf);
751 KEYWORD(norm);
752 KEYWORD(nnorm);
753 KEYWORD(pnorm);
754 // sub already a keyword
755 KEYWORD(nsub);
756 KEYWORD(psub);
757 KEYWORD(zero);
758 KEYWORD(nzero);
759 KEYWORD(pzero);
760
761 KEYWORD(type);
762 KEYWORD(opaque);
763
764 KEYWORD(comdat);
765
766 // Comdat types
767 KEYWORD(any);
768 KEYWORD(exactmatch);
769 KEYWORD(largest);
770 KEYWORD(nodeduplicate);
771 KEYWORD(samesize);
772
773 KEYWORD(eq); KEYWORD(ne); KEYWORD(slt); KEYWORD(sgt); KEYWORD(sle);
774 KEYWORD(sge); KEYWORD(ult); KEYWORD(ugt); KEYWORD(ule); KEYWORD(uge);
775 KEYWORD(oeq); KEYWORD(one); KEYWORD(olt); KEYWORD(ogt); KEYWORD(ole);
776 KEYWORD(oge); KEYWORD(ord); KEYWORD(uno); KEYWORD(ueq); KEYWORD(une);
777
778 KEYWORD(xchg); KEYWORD(nand); KEYWORD(max); KEYWORD(min); KEYWORD(umax);
779 KEYWORD(umin); KEYWORD(fmax); KEYWORD(fmin);
780 KEYWORD(fmaximum);
781 KEYWORD(fminimum);
782 KEYWORD(fmaximumnum);
783 KEYWORD(fminimumnum);
784 KEYWORD(uinc_wrap);
785 KEYWORD(udec_wrap);
786 KEYWORD(usub_cond);
787 KEYWORD(usub_sat);
788
789 KEYWORD(splat);
790 KEYWORD(vscale);
791 KEYWORD(x);
792 KEYWORD(blockaddress);
793 KEYWORD(dso_local_equivalent);
794 KEYWORD(no_cfi);
795 KEYWORD(ptrauth);
796
797 // Metadata types.
798 KEYWORD(distinct);
799
800 // Use-list order directives.
801 KEYWORD(uselistorder);
802 KEYWORD(uselistorder_bb);
803
804 KEYWORD(personality);
806 KEYWORD(catch);
807 KEYWORD(filter);
808
809 // Summary index keywords.
810 KEYWORD(path);
811 KEYWORD(hash);
812 KEYWORD(gv);
813 KEYWORD(guid);
814 KEYWORD(name);
815 KEYWORD(summaries);
816 KEYWORD(flags);
817 KEYWORD(blockcount);
818 KEYWORD(linkage);
819 KEYWORD(visibility);
820 KEYWORD(notEligibleToImport);
821 KEYWORD(live);
822 KEYWORD(dsoLocal);
823 KEYWORD(canAutoHide);
824 KEYWORD(importType);
825 KEYWORD(definition);
826 KEYWORD(declaration);
827 KEYWORD(noRenameOnPromotion);
829 KEYWORD(insts);
830 KEYWORD(funcFlags);
831 KEYWORD(readNone);
832 KEYWORD(readOnly);
833 KEYWORD(noRecurse);
834 KEYWORD(returnDoesNotAlias);
835 KEYWORD(noInline);
836 KEYWORD(alwaysInline);
837 KEYWORD(noUnwind);
838 KEYWORD(mayThrow);
839 KEYWORD(hasUnknownCall);
840 KEYWORD(mustBeUnreachable);
841 KEYWORD(calls);
842 KEYWORD(callee);
843 KEYWORD(params);
844 KEYWORD(param);
845 KEYWORD(hotness);
846 KEYWORD(unknown);
847 KEYWORD(critical);
848 // Deprecated, keep in order to support old files.
849 KEYWORD(relbf);
850 KEYWORD(variable);
851 KEYWORD(vTableFuncs);
852 KEYWORD(virtFunc);
853 KEYWORD(aliasee);
854 KEYWORD(refs);
855 KEYWORD(typeIdInfo);
856 KEYWORD(typeTests);
857 KEYWORD(typeTestAssumeVCalls);
858 KEYWORD(typeCheckedLoadVCalls);
859 KEYWORD(typeTestAssumeConstVCalls);
860 KEYWORD(typeCheckedLoadConstVCalls);
861 KEYWORD(vFuncId);
862 KEYWORD(offset);
863 KEYWORD(args);
864 KEYWORD(typeid);
865 KEYWORD(typeidCompatibleVTable);
866 KEYWORD(summary);
867 KEYWORD(typeTestRes);
868 KEYWORD(kind);
869 KEYWORD(unsat);
870 KEYWORD(byteArray);
871 KEYWORD(inline);
872 KEYWORD(single);
874 KEYWORD(sizeM1BitWidth);
875 KEYWORD(alignLog2);
876 KEYWORD(sizeM1);
877 KEYWORD(bitMask);
878 KEYWORD(inlineBits);
879 KEYWORD(vcall_visibility);
880 KEYWORD(wpdResolutions);
881 KEYWORD(wpdRes);
882 KEYWORD(indir);
883 KEYWORD(singleImpl);
884 KEYWORD(branchFunnel);
885 KEYWORD(singleImplName);
886 KEYWORD(resByArg);
887 KEYWORD(byArg);
888 KEYWORD(uniformRetVal);
889 KEYWORD(uniqueRetVal);
890 KEYWORD(virtualConstProp);
891 KEYWORD(info);
892 KEYWORD(byte);
893 KEYWORD(bit);
894 KEYWORD(varFlags);
895 KEYWORD(callsites);
896 KEYWORD(clones);
897 KEYWORD(stackIds);
898 KEYWORD(allocs);
899 KEYWORD(versions);
900 KEYWORD(memProf);
901 KEYWORD(notcold);
902
903#undef KEYWORD
904
905 // Keywords for types.
906#define TYPEKEYWORD(STR, LLVMTY) \
907 do { \
908 if (Keyword == STR) { \
909 TyVal = LLVMTY; \
910 return lltok::Type; \
911 } \
912 } while (false)
913
914 TYPEKEYWORD("void", Type::getVoidTy(Context));
915 TYPEKEYWORD("half", Type::getHalfTy(Context));
916 TYPEKEYWORD("bfloat", Type::getBFloatTy(Context));
917 TYPEKEYWORD("float", Type::getFloatTy(Context));
918 TYPEKEYWORD("double", Type::getDoubleTy(Context));
919 TYPEKEYWORD("x86_fp80", Type::getX86_FP80Ty(Context));
920 TYPEKEYWORD("fp128", Type::getFP128Ty(Context));
921 TYPEKEYWORD("ppc_fp128", Type::getPPC_FP128Ty(Context));
922 TYPEKEYWORD("label", Type::getLabelTy(Context));
923 TYPEKEYWORD("metadata", Type::getMetadataTy(Context));
924 TYPEKEYWORD("x86_amx", Type::getX86_AMXTy(Context));
925 TYPEKEYWORD("token", Type::getTokenTy(Context));
926 TYPEKEYWORD("ptr", PointerType::getUnqual(Context));
927
928#undef TYPEKEYWORD
929
930 // Keywords for instructions.
931#define INSTKEYWORD(STR, Enum) \
932 do { \
933 if (Keyword == #STR) { \
934 UIntVal = Instruction::Enum; \
935 return lltok::kw_##STR; \
936 } \
937 } while (false)
938
939 INSTKEYWORD(fneg, FNeg);
940
941 INSTKEYWORD(add, Add); INSTKEYWORD(fadd, FAdd);
942 INSTKEYWORD(sub, Sub); INSTKEYWORD(fsub, FSub);
943 INSTKEYWORD(mul, Mul); INSTKEYWORD(fmul, FMul);
944 INSTKEYWORD(udiv, UDiv); INSTKEYWORD(sdiv, SDiv); INSTKEYWORD(fdiv, FDiv);
945 INSTKEYWORD(urem, URem); INSTKEYWORD(srem, SRem); INSTKEYWORD(frem, FRem);
946 INSTKEYWORD(shl, Shl); INSTKEYWORD(lshr, LShr); INSTKEYWORD(ashr, AShr);
947 INSTKEYWORD(and, And); INSTKEYWORD(or, Or); INSTKEYWORD(xor, Xor);
948 INSTKEYWORD(icmp, ICmp); INSTKEYWORD(fcmp, FCmp);
949
950 INSTKEYWORD(phi, PHI);
951 INSTKEYWORD(call, Call);
952 INSTKEYWORD(trunc, Trunc);
953 INSTKEYWORD(zext, ZExt);
954 INSTKEYWORD(sext, SExt);
955 INSTKEYWORD(fptrunc, FPTrunc);
956 INSTKEYWORD(fpext, FPExt);
957 INSTKEYWORD(uitofp, UIToFP);
958 INSTKEYWORD(sitofp, SIToFP);
959 INSTKEYWORD(fptoui, FPToUI);
960 INSTKEYWORD(fptosi, FPToSI);
961 INSTKEYWORD(inttoptr, IntToPtr);
962 INSTKEYWORD(ptrtoaddr, PtrToAddr);
963 INSTKEYWORD(ptrtoint, PtrToInt);
964 INSTKEYWORD(bitcast, BitCast);
965 INSTKEYWORD(addrspacecast, AddrSpaceCast);
966 INSTKEYWORD(select, Select);
967 INSTKEYWORD(va_arg, VAArg);
968 INSTKEYWORD(ret, Ret);
969 INSTKEYWORD(switch, Switch);
970 INSTKEYWORD(indirectbr, IndirectBr);
971 INSTKEYWORD(invoke, Invoke);
972 INSTKEYWORD(resume, Resume);
973 INSTKEYWORD(unreachable, Unreachable);
974 INSTKEYWORD(callbr, CallBr);
975
976 INSTKEYWORD(alloca, Alloca);
977 INSTKEYWORD(load, Load);
978 INSTKEYWORD(store, Store);
979 INSTKEYWORD(cmpxchg, AtomicCmpXchg);
980 INSTKEYWORD(atomicrmw, AtomicRMW);
981 INSTKEYWORD(fence, Fence);
982 INSTKEYWORD(getelementptr, GetElementPtr);
983
984 INSTKEYWORD(extractelement, ExtractElement);
985 INSTKEYWORD(insertelement, InsertElement);
986 INSTKEYWORD(shufflevector, ShuffleVector);
987 INSTKEYWORD(extractvalue, ExtractValue);
988 INSTKEYWORD(insertvalue, InsertValue);
989 INSTKEYWORD(landingpad, LandingPad);
990 INSTKEYWORD(cleanupret, CleanupRet);
991 INSTKEYWORD(catchret, CatchRet);
992 INSTKEYWORD(catchswitch, CatchSwitch);
993 INSTKEYWORD(catchpad, CatchPad);
994 INSTKEYWORD(cleanuppad, CleanupPad);
995
996 INSTKEYWORD(freeze, Freeze);
997
998#undef INSTKEYWORD
999
1000#define DWKEYWORD(TYPE, TOKEN) \
1001 do { \
1002 if (Keyword.starts_with("DW_" #TYPE "_")) { \
1003 StrVal.assign(Keyword.begin(), Keyword.end()); \
1004 return lltok::TOKEN; \
1005 } \
1006 } while (false)
1007
1008 DWKEYWORD(TAG, DwarfTag);
1009 DWKEYWORD(ATE, DwarfAttEncoding);
1010 DWKEYWORD(VIRTUALITY, DwarfVirtuality);
1011 DWKEYWORD(LANG, DwarfLang);
1012 DWKEYWORD(LNAME, DwarfSourceLangName);
1013 DWKEYWORD(CC, DwarfCC);
1014 DWKEYWORD(OP, DwarfOp);
1015 DWKEYWORD(MACINFO, DwarfMacinfo);
1016 DWKEYWORD(APPLE_ENUM_KIND, DwarfEnumKind);
1017
1018#undef DWKEYWORD
1019
1020// Keywords for debug record types.
1021#define DBGRECORDTYPEKEYWORD(STR) \
1022 do { \
1023 if (Keyword == "dbg_" #STR) { \
1024 StrVal = #STR; \
1025 return lltok::DbgRecordType; \
1026 } \
1027 } while (false)
1028
1029 DBGRECORDTYPEKEYWORD(value);
1030 DBGRECORDTYPEKEYWORD(declare);
1031 DBGRECORDTYPEKEYWORD(assign);
1032 DBGRECORDTYPEKEYWORD(label);
1033 DBGRECORDTYPEKEYWORD(declare_value);
1034#undef DBGRECORDTYPEKEYWORD
1035
1036 if (Keyword.starts_with("DIFlag")) {
1037 StrVal.assign(Keyword.begin(), Keyword.end());
1038 return lltok::DIFlag;
1039 }
1040
1041 if (Keyword.starts_with("DISPFlag")) {
1042 StrVal.assign(Keyword.begin(), Keyword.end());
1043 return lltok::DISPFlag;
1044 }
1045
1046 if (Keyword.starts_with("CSK_")) {
1047 StrVal.assign(Keyword.begin(), Keyword.end());
1048 return lltok::ChecksumKind;
1049 }
1050
1051 if (Keyword == "NoDebug" || Keyword == "FullDebug" ||
1052 Keyword == "LineTablesOnly" || Keyword == "DebugDirectivesOnly") {
1053 StrVal.assign(Keyword.begin(), Keyword.end());
1054 return lltok::EmissionKind;
1055 }
1056
1057 if (Keyword == "GNU" || Keyword == "Apple" || Keyword == "None" ||
1058 Keyword == "Default") {
1059 StrVal.assign(Keyword.begin(), Keyword.end());
1060 return lltok::NameTableKind;
1061 }
1062
1063 if (Keyword == "Binary" || Keyword == "Decimal" || Keyword == "Rational") {
1064 StrVal.assign(Keyword.begin(), Keyword.end());
1065 return lltok::FixedPointKind;
1066 }
1067
1068 // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
1069 // the CFE to avoid forcing it to deal with 64-bit numbers.
1070 if ((TokStart[0] == 'u' || TokStart[0] == 's') &&
1071 TokStart[1] == '0' && TokStart[2] == 'x' &&
1072 isxdigit(static_cast<unsigned char>(TokStart[3]))) {
1073 int len = CurPtr-TokStart-3;
1074 uint32_t bits = len * 4;
1075 StringRef HexStr(TokStart + 3, len);
1076 if (!all_of(HexStr, isxdigit)) {
1077 // Bad token, return it as an error.
1078 CurPtr = TokStart+3;
1079 return lltok::Error;
1080 }
1081 APInt Tmp(bits, HexStr, 16);
1082 uint32_t activeBits = Tmp.getActiveBits();
1083 if (activeBits > 0 && activeBits < bits)
1084 Tmp = Tmp.trunc(activeBits);
1085 APSIntVal = APSInt(Tmp, TokStart[0] == 'u');
1086 return lltok::APSInt;
1087 }
1088
1089 // If this is "cc1234", return this as just "cc".
1090 if (TokStart[0] == 'c' && TokStart[1] == 'c') {
1091 CurPtr = TokStart+2;
1092 return lltok::kw_cc;
1093 }
1094
1095 // Finally, if this isn't known, return an error.
1096 CurPtr = TokStart+1;
1097 return lltok::Error;
1098}
1099
1100/// Lex all tokens that start with a 0x prefix, knowing they match and are not
1101/// labels.
1102/// HexFPConstant 0x[0-9A-Fa-f]+
1103/// HexFP80Constant 0xK[0-9A-Fa-f]+
1104/// HexFP128Constant 0xL[0-9A-Fa-f]+
1105/// HexPPC128Constant 0xM[0-9A-Fa-f]+
1106/// HexHalfConstant 0xH[0-9A-Fa-f]+
1107/// HexBFloatConstant 0xR[0-9A-Fa-f]+
1108lltok::Kind LLLexer::Lex0x() {
1109 CurPtr = TokStart + 2;
1110
1111 char Kind;
1112 if ((CurPtr[0] >= 'K' && CurPtr[0] <= 'M') || CurPtr[0] == 'H' ||
1113 CurPtr[0] == 'R') {
1114 Kind = *CurPtr++;
1115 } else {
1116 Kind = 'J';
1117 }
1118
1119 if (!isxdigit(static_cast<unsigned char>(CurPtr[0]))) {
1120 // Bad token, return it as an error.
1121 CurPtr = TokStart+1;
1122 return lltok::Error;
1123 }
1124
1125 while (isxdigit(static_cast<unsigned char>(CurPtr[0])))
1126 ++CurPtr;
1127
1128 if (Kind == 'J') {
1129 // HexFPConstant - Floating point constant represented in IEEE format as a
1130 // hexadecimal number for when exponential notation is not precise enough.
1131 // Half, BFloat, Float, and double only.
1132 APFloatVal = APFloat(APFloat::IEEEdouble(),
1133 APInt(64, HexIntToVal(TokStart + 2, CurPtr)));
1134 return lltok::APFloat;
1135 }
1136
1137 uint64_t Pair[2];
1138 switch (Kind) {
1139 default: llvm_unreachable("Unknown kind!");
1140 case 'K':
1141 // F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
1142 FP80HexToIntPair(TokStart+3, CurPtr, Pair);
1143 APFloatVal = APFloat(APFloat::x87DoubleExtended(), APInt(80, Pair));
1144 return lltok::APFloat;
1145 case 'L':
1146 // F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
1147 HexToIntPair(TokStart+3, CurPtr, Pair);
1148 APFloatVal = APFloat(APFloat::IEEEquad(), APInt(128, Pair));
1149 return lltok::APFloat;
1150 case 'M':
1151 // PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
1152 HexToIntPair(TokStart+3, CurPtr, Pair);
1153 APFloatVal = APFloat(APFloat::PPCDoubleDouble(), APInt(128, Pair));
1154 return lltok::APFloat;
1155 case 'H': {
1156 uint64_t Val = HexIntToVal(TokStart + 3, CurPtr);
1157 if (!llvm::isUInt<16>(Val)) {
1158 LexError("hexadecimal constant too large for half (16-bit)");
1159 return lltok::Error;
1160 }
1161 APFloatVal = APFloat(APFloat::IEEEhalf(), APInt(16, Val));
1162 return lltok::APFloat;
1163 }
1164 case 'R': {
1165 // Brain floating point
1166 uint64_t Val = HexIntToVal(TokStart + 3, CurPtr);
1167 if (!llvm::isUInt<16>(Val)) {
1168 LexError("hexadecimal constant too large for bfloat (16-bit)");
1169 return lltok::Error;
1170 }
1171 APFloatVal = APFloat(APFloat::BFloat(), APInt(16, Val));
1172 return lltok::APFloat;
1173 }
1174 }
1175}
1176
1177/// Lex tokens for a label or a numeric constant, possibly starting with -.
1178/// Label [-a-zA-Z$._0-9]+:
1179/// NInteger -[0-9]+
1180/// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
1181/// PInteger [0-9]+
1182/// HexFPConstant 0x[0-9A-Fa-f]+
1183/// HexFP80Constant 0xK[0-9A-Fa-f]+
1184/// HexFP128Constant 0xL[0-9A-Fa-f]+
1185/// HexPPC128Constant 0xM[0-9A-Fa-f]+
1186lltok::Kind LLLexer::LexDigitOrNegative() {
1187 // If the letter after the negative is not a number, this is probably a label.
1188 if (!isdigit(static_cast<unsigned char>(TokStart[0])) &&
1189 !isdigit(static_cast<unsigned char>(CurPtr[0]))) {
1190 // Okay, this is not a number after the -, it's probably a label.
1191 if (const char *End = isLabelTail(CurPtr)) {
1192 StrVal.assign(TokStart, End-1);
1193 CurPtr = End;
1194 return lltok::LabelStr;
1195 }
1196
1197 return lltok::Error;
1198 }
1199
1200 // At this point, it is either a label, int or fp constant.
1201
1202 // Skip digits, we have at least one.
1203 for (; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
1204 /*empty*/;
1205
1206 // Check if this is a fully-numeric label:
1207 if (isdigit(TokStart[0]) && CurPtr[0] == ':') {
1208 uint64_t Val = atoull(TokStart, CurPtr);
1209 ++CurPtr; // Skip the colon.
1210 if ((unsigned)Val != Val)
1211 LexError("invalid value number (too large)");
1212 UIntVal = unsigned(Val);
1213 return lltok::LabelID;
1214 }
1215
1216 // Check to see if this really is a string label, e.g. "-1:".
1217 if (isLabelChar(CurPtr[0]) || CurPtr[0] == ':') {
1218 if (const char *End = isLabelTail(CurPtr)) {
1219 StrVal.assign(TokStart, End-1);
1220 CurPtr = End;
1221 return lltok::LabelStr;
1222 }
1223 }
1224
1225 // If the next character is a '.', then it is a fp value, otherwise its
1226 // integer.
1227 if (CurPtr[0] != '.') {
1228 if (TokStart[0] == '0' && TokStart[1] == 'x')
1229 return Lex0x();
1230 APSIntVal = APSInt(StringRef(TokStart, CurPtr - TokStart));
1231 return lltok::APSInt;
1232 }
1233
1234 ++CurPtr;
1235
1236 // Skip over [0-9]*([eE][-+]?[0-9]+)?
1237 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1238
1239 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
1240 if (isdigit(static_cast<unsigned char>(CurPtr[1])) ||
1241 ((CurPtr[1] == '-' || CurPtr[1] == '+') &&
1242 isdigit(static_cast<unsigned char>(CurPtr[2])))) {
1243 CurPtr += 2;
1244 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1245 }
1246 }
1247
1248 APFloatVal = APFloat(APFloat::IEEEdouble(),
1249 StringRef(TokStart, CurPtr - TokStart));
1250 return lltok::APFloat;
1251}
1252
1253/// Lex a floating point constant starting with +.
1254/// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
1255lltok::Kind LLLexer::LexPositive() {
1256 // If the letter after the negative is a number, this is probably not a
1257 // label.
1258 if (!isdigit(static_cast<unsigned char>(CurPtr[0])))
1259 return lltok::Error;
1260
1261 // Skip digits.
1262 for (++CurPtr; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
1263 /*empty*/;
1264
1265 // At this point, we need a '.'.
1266 if (CurPtr[0] != '.') {
1267 CurPtr = TokStart+1;
1268 return lltok::Error;
1269 }
1270
1271 ++CurPtr;
1272
1273 // Skip over [0-9]*([eE][-+]?[0-9]+)?
1274 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1275
1276 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
1277 if (isdigit(static_cast<unsigned char>(CurPtr[1])) ||
1278 ((CurPtr[1] == '-' || CurPtr[1] == '+') &&
1279 isdigit(static_cast<unsigned char>(CurPtr[2])))) {
1280 CurPtr += 2;
1281 while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
1282 }
1283 }
1284
1285 APFloatVal = APFloat(APFloat::IEEEdouble(),
1286 StringRef(TokStart, CurPtr - TokStart));
1287 return lltok::APFloat;
1288}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Mark last scratch load
AMDGPU Register Bank Select
Rewrite undef for PHI
This file implements a class to represent arbitrary precision integral constant values and operations...
static void cleanup(BlockFrequencyInfoImplBase &BFI)
Clear all memory not needed downstream.
static void zero(T &Obj)
expand ir insts
static void UnEscapeLexed(std::string &Str)
Definition LLLexer.cpp:126
static const char * isLabelTail(const char *CurPtr)
isLabelTail - Return true if this pointer points to a valid end of a label.
Definition LLLexer.cpp:159
#define DBGRECORDTYPEKEYWORD(STR)
static bool isLabelChar(char C)
isLabelChar - Return true for [-a-zA-Z$._0-9].
Definition LLLexer.cpp:153
#define TYPEKEYWORD(STR, LLVMTY)
#define DWKEYWORD(TYPE, TOKEN)
#define INSTKEYWORD(STR, Enum)
#define KEYWORD(STR)
lazy value info
nvptx lower args
objc arc contract
static constexpr auto TAG
dot regions Print regions of function to dot true view regions View regions of function(with no function bodies)"
static const char * name
This file contains some templates that are useful if you are working with the STL at all.
#define OP(OPC)
Definition Instruction.h:46
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
Definition Value.cpp:487
This file contains some functions that are useful when dealing with strings.
static uint64_t allOnes(unsigned int Count)
static const fltSemantics & BFloat()
Definition APFloat.h:295
static const fltSemantics & IEEEquad()
Definition APFloat.h:298
static const fltSemantics & IEEEdouble()
Definition APFloat.h:297
static const fltSemantics & x87DoubleExtended()
Definition APFloat.h:317
static const fltSemantics & IEEEhalf()
Definition APFloat.h:294
static const fltSemantics & PPCDoubleDouble()
Definition APFloat.h:299
static LLVM_ABI ByteType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing a ByteType.
Definition Type.cpp:384
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static LLVM_ABI IntegerType * get(LLVMContext &C, unsigned NumBits)
This static method is the primary way of constructing an IntegerType.
Definition Type.cpp:354
@ MIN_INT_BITS
Minimum number of bits that can be specified.
@ MAX_INT_BITS
Maximum number of bits that can be specified.
void Warning(LocTy WarningLoc, const Twine &Msg) const
Definition LLLexer.cpp:45
LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &, LLVMContext &C)
Definition LLLexer.cpp:171
SMLoc LocTy
Definition LLLexer.h:70
This is an important class for using LLVM in a threaded context.
Definition LLVMContext.h:68
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Instances of this class encapsulate one diagnostic report, allowing printing to a raw_ostream as a ca...
Definition SourceMgr.h:297
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
Definition SourceMgr.h:37
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
iterator end() const
Definition StringRef.h:115
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
static LLVM_ABI Type * getX86_AMXTy(LLVMContext &C)
Definition Type.cpp:297
static LLVM_ABI Type * getMetadataTy(LLVMContext &C)
Definition Type.cpp:292
static LLVM_ABI Type * getTokenTy(LLVMContext &C)
Definition Type.cpp:293
static LLVM_ABI Type * getPPC_FP128Ty(LLVMContext &C)
Definition Type.cpp:296
static LLVM_ABI Type * getFP128Ty(LLVMContext &C)
Definition Type.cpp:295
static LLVM_ABI Type * getLabelTy(LLVMContext &C)
Definition Type.cpp:287
static LLVM_ABI Type * getVoidTy(LLVMContext &C)
Definition Type.cpp:286
static LLVM_ABI Type * getDoubleTy(LLVMContext &C)
Definition Type.cpp:291
static LLVM_ABI Type * getX86_FP80Ty(LLVMContext &C)
Definition Type.cpp:294
static LLVM_ABI Type * getFloatTy(LLVMContext &C)
Definition Type.cpp:290
static LLVM_ABI Type * getBFloatTy(LLVMContext &C)
Definition Type.cpp:289
static LLVM_ABI Type * getHalfTy(LLVMContext &C)
Definition Type.cpp:288
CallInst * Call
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
@ StringConstant
Definition LLToken.h:509
@ NameTableKind
Definition LLToken.h:517
@ FixedPointKind
Definition LLToken.h:518
This is an optimization pass for GlobalISel generic memory operations.
Definition Types.h:26
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
std::tuple< const DIScope *, const DIScope *, const DILocalVariable * > VarID
A unique key that represents a debug variable.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1739
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
constexpr std::invoke_result_t< FnT, ArgsT... > invoke(FnT &&Fn, ArgsT &&...Args)
C++20 constexpr invoke.
LLVM_ABI FPClassTest fneg(FPClassTest Mask)
Return the test mask which returns true if the value's sign bit is flipped.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
Definition MathExtras.h:189
@ Or
Bitwise or logical OR of integers.
@ Mul
Product of integers.
@ Xor
Bitwise or logical XOR of integers.
@ FMul
Product of floats.
@ And
Bitwise or logical AND of integers.
@ Sub
Subtraction of integers.
@ Add
Sum of integers.
@ FAdd
Sum of floats.
auto partition(R &&Range, UnaryPredicate P)
Provide wrappers to std::partition which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:2033
LLVM_ABI Error write(MCStreamer &Out, ArrayRef< std::string > Inputs, OnCuIndexOverflow OverflowOptValue, Dwarf64StrOffsetsPromotion StrOffsetsOptValue)
Definition DWP.cpp:677