LLVM: lib/MC/MCParser/AsmLexer.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
23#include
24#include
25#include
26#include
27#include
28
29using namespace llvm;
30
32
36
38
40 switch (Kind) {
42 OS << "error";
43 break;
45 OS << "identifier: " << getString();
46 break;
49 break;
52 break;
55 break;
56
57
101
102 }
103
104
105 OS << " (\"";
107 OS << "\")";
108}
109
111
112
114 MAI.useAtForSpecifier();
115 LexMotorolaIntegers = MAI.shouldUseMotorolaIntegers();
116
118}
119
121 bool EndStatementAtEOF) {
122
123
125 "Buffer provided to AsmLexer lacks null terminator.");
126
127 CurBuf = Buf;
128
129 if (ptr)
130 CurPtr = ptr;
131 else
132 CurPtr = CurBuf.begin();
133
134 TokStart = nullptr;
135 this->EndStatementAtEOF = EndStatementAtEOF;
136}
137
138
139
140AsmToken AsmLexer::ReturnError(const char *Loc, const std::string &Msg) {
142
144}
145
146int AsmLexer::getNextChar() {
147 if (CurPtr == CurBuf.end())
148 return EOF;
149 return (unsigned char)*CurPtr++;
150}
151
152int AsmLexer::peekNextChar() {
153 if (CurPtr == CurBuf.end())
154 return EOF;
155 return (unsigned char)*CurPtr;
156}
157
158
159
160
161AsmToken AsmLexer::LexFloatLiteral() {
162
164 ++CurPtr;
165
166 if (*CurPtr == '-' || *CurPtr == '+')
167 return ReturnError(CurPtr, "invalid sign in float literal");
168
169
170 if ((*CurPtr == 'e' || *CurPtr == 'E')) {
171 ++CurPtr;
172
173 if (*CurPtr == '-' || *CurPtr == '+')
174 ++CurPtr;
175
177 ++CurPtr;
178 }
179
181 StringRef(TokStart, CurPtr - TokStart));
182}
183
184
185
186
187
188
189
190AsmToken AsmLexer::LexHexFloatLiteral(bool NoIntDigits) {
191 assert((*CurPtr == 'p' || *CurPtr == 'P' || *CurPtr == '.') &&
192 "unexpected parse state in floating hex");
193 bool NoFracDigits = true;
194
195
196 if (*CurPtr == '.') {
197 ++CurPtr;
198
199 const char *FracStart = CurPtr;
201 ++CurPtr;
202
203 NoFracDigits = CurPtr == FracStart;
204 }
205
206 if (NoIntDigits && NoFracDigits)
207 return ReturnError(TokStart, "invalid hexadecimal floating-point constant: "
208 "expected at least one significand digit");
209
210
211 if (*CurPtr != 'p' && *CurPtr != 'P')
212 return ReturnError(TokStart, "invalid hexadecimal floating-point constant: "
213 "expected exponent part 'p'");
214 ++CurPtr;
215
216 if (*CurPtr == '+' || *CurPtr == '-')
217 ++CurPtr;
218
219
220 const char *ExpStart = CurPtr;
222 ++CurPtr;
223
224 if (CurPtr == ExpStart)
225 return ReturnError(TokStart, "invalid hexadecimal floating-point constant: "
226 "expected at least one exponent digit");
227
228 return AsmToken(AsmToken::Real, StringRef(TokStart, CurPtr - TokStart));
229}
230
231
233 return isAlnum(C) || C == '_' || C == '$' || C == '.' || C == '?' ||
234 (AllowAt && C == '@') || (AllowHash && C == '#');
235}
236
237AsmToken AsmLexer::LexIdentifier() {
238
239 if (CurPtr[-1] == '.' && isDigit(*CurPtr)) {
240
242 ++CurPtr;
243
245 AllowHashInIdentifier) ||
246 *CurPtr == 'e' || *CurPtr == 'E')
247 return LexFloatLiteral();
248 }
249
250 while (isIdentifierChar(*CurPtr, AllowAtInIdentifier, AllowHashInIdentifier))
251 ++CurPtr;
252
253
254 if (CurPtr == TokStart+1 && TokStart[0] == '.')
255 return AsmToken(AsmToken::Dot, StringRef(TokStart, 1));
256
257 return AsmToken(AsmToken::Identifier, StringRef(TokStart, CurPtr - TokStart));
258}
259
260
261
262
263AsmToken AsmLexer::LexSlash() {
264 if (!MAI.shouldAllowAdditionalComments()) {
265 IsAtStartOfStatement = false;
266 return AsmToken(AsmToken::Slash, StringRef(TokStart, 1));
267 }
268
269 switch (*CurPtr) {
270 case '*':
271 IsAtStartOfStatement = false;
272 break;
273 case '/':
274 ++CurPtr;
275 return LexLineComment();
276 default:
277 IsAtStartOfStatement = false;
278 return AsmToken(AsmToken::Slash, StringRef(TokStart, 1));
279 }
280
281
282 ++CurPtr;
283 const char *CommentTextStart = CurPtr;
284 while (CurPtr != CurBuf.end()) {
285 switch (*CurPtr++) {
286 case '*':
287
288 if (*CurPtr != '/')
289 break;
290
291 if (CommentConsumer) {
292 CommentConsumer->HandleComment(
294 StringRef(CommentTextStart, CurPtr - 1 - CommentTextStart));
295 }
296 ++CurPtr;
298 StringRef(TokStart, CurPtr - TokStart));
299 }
300 }
301 return ReturnError(TokStart, "unterminated comment");
302}
303
304
305
306AsmToken AsmLexer::LexLineComment() {
307
308
309
310
311 const char *CommentTextStart = CurPtr;
312 int CurChar = getNextChar();
313 while (CurChar != '\n' && CurChar != '\r' && CurChar != EOF)
314 CurChar = getNextChar();
315 const char *NewlinePtr = CurPtr;
316 if (CurChar == '\r' && CurPtr != CurBuf.end() && *CurPtr == '\n')
317 ++CurPtr;
318
319
320 if (CommentConsumer) {
321 CommentConsumer->HandleComment(
323 StringRef(CommentTextStart, NewlinePtr - 1 - CommentTextStart));
324 }
325
326 IsAtStartOfLine = true;
327
328 if (IsAtStartOfStatement)
330 StringRef(TokStart, CurPtr - TokStart));
331 IsAtStartOfStatement = true;
332
334 StringRef(TokStart, CurPtr - 1 - TokStart));
335}
336
338
339 if (CurPtr[0] == 'U' || CurPtr[0] == 'u')
340 ++CurPtr;
341 if (CurPtr[0] == 'L' || CurPtr[0] == 'l')
342 ++CurPtr;
343 if (CurPtr[0] == 'L' || CurPtr[0] == 'l')
344 ++CurPtr;
345}
346
347
348
349static unsigned doHexLookAhead(const char *&CurPtr, unsigned DefaultRadix,
350 bool LexHex) {
351 const char *FirstNonDec = nullptr;
352 const char *LookAhead = CurPtr;
353 while (true) {
354 if (isDigit(*LookAhead)) {
355 ++LookAhead;
356 } else {
357 if (!FirstNonDec)
358 FirstNonDec = LookAhead;
359
360
361 if (LexHex && isHexDigit(*LookAhead))
362 ++LookAhead;
363 else
364 break;
365 }
366 }
367 bool isHex = LexHex && (*LookAhead == 'h' || *LookAhead == 'H');
368 CurPtr = isHex || !FirstNonDec ? LookAhead : FirstNonDec;
369 if (isHex)
370 return 16;
371 return DefaultRadix;
372}
373
374static const char *findLastDigit(const char *CurPtr, unsigned DefaultRadix) {
376 ++CurPtr;
377 }
378 return CurPtr;
379}
380
382 if (Value.isIntN(64))
385}
386
387static std::string radixName(unsigned Radix) {
388 switch (Radix) {
389 case 2:
390 return "binary";
391 case 8:
392 return "octal";
393 case 10:
394 return "decimal";
395 case 16:
396 return "hexadecimal";
397 default:
398 return "base-" + std::to_string(Radix);
399 }
400}
401
402
403
404
405
406
407
408
409AsmToken AsmLexer::LexDigit() {
410
411
412
413
414 if (LexMasmIntegers && isdigit(CurPtr[-1])) {
415 const char *FirstNonBinary =
416 (CurPtr[-1] != '0' && CurPtr[-1] != '1') ? CurPtr - 1 : nullptr;
417 const char *FirstNonDecimal =
418 (CurPtr[-1] < '0' || CurPtr[-1] > '9') ? CurPtr - 1 : nullptr;
419 const char *OldCurPtr = CurPtr;
421 switch (*CurPtr) {
422 default:
423 if (!FirstNonDecimal) {
424 FirstNonDecimal = CurPtr;
425 }
426 [[fallthrough]];
427 case '9':
428 case '8':
429 case '7':
430 case '6':
431 case '5':
432 case '4':
433 case '3':
434 case '2':
435 if (!FirstNonBinary) {
436 FirstNonBinary = CurPtr;
437 }
438 break;
439 case '1':
440 case '0':
441 break;
442 }
443 ++CurPtr;
444 }
445 if (*CurPtr == '.') {
446
447
448 ++CurPtr;
449 return LexFloatLiteral();
450 }
451
452 if (LexMasmHexFloats && (*CurPtr == 'r' || *CurPtr == 'R')) {
453 ++CurPtr;
454 return AsmToken(AsmToken::Real, StringRef(TokStart, CurPtr - TokStart));
455 }
456
457 unsigned Radix = 0;
458 if (*CurPtr == 'h' || *CurPtr == 'H') {
459
460 ++CurPtr;
461 Radix = 16;
462 } else if (*CurPtr == 't' || *CurPtr == 'T') {
463
464 ++CurPtr;
465 Radix = 10;
466 } else if (*CurPtr == 'o' || *CurPtr == 'O' || *CurPtr == 'q' ||
467 *CurPtr == 'Q') {
468
469 ++CurPtr;
470 Radix = 8;
471 } else if (*CurPtr == 'y' || *CurPtr == 'Y') {
472
473 ++CurPtr;
474 Radix = 2;
475 } else if (FirstNonDecimal && FirstNonDecimal + 1 == CurPtr &&
476 DefaultRadix < 14 &&
477 (*FirstNonDecimal == 'd' || *FirstNonDecimal == 'D')) {
478 Radix = 10;
479 } else if (FirstNonBinary && FirstNonBinary + 1 == CurPtr &&
480 DefaultRadix < 12 &&
481 (*FirstNonBinary == 'b' || *FirstNonBinary == 'B')) {
482 Radix = 2;
483 }
484
485 if (Radix) {
486 StringRef Result(TokStart, CurPtr - TokStart);
487 APInt Value(128, 0, true);
488
489 if (Result.drop_back().getAsInteger(Radix, Value))
490 return ReturnError(TokStart, "invalid " + radixName(Radix) + " number");
491
492
494
496 }
497
498
499 CurPtr = OldCurPtr;
500 }
501
502
503
504 if (LexMasmIntegers && UseMasmDefaultRadix) {
506 StringRef Result(TokStart, CurPtr - TokStart);
507
508 APInt Value(128, 0, true);
509 if (Result.getAsInteger(DefaultRadix, Value)) {
510 return ReturnError(TokStart,
511 "invalid " + radixName(DefaultRadix) + " number");
512 }
513
515 }
516
517
518 if (LexMotorolaIntegers && CurPtr[-1] == '$') {
519 const char *NumStart = CurPtr;
521 ++CurPtr;
522
523 APInt Result(128, 0);
524 if (StringRef(NumStart, CurPtr - NumStart).getAsInteger(16, Result))
525 return ReturnError(TokStart, "invalid hexadecimal number");
526
527 return intToken(StringRef(TokStart, CurPtr - TokStart), Result);
528 }
529
530
531 if (LexMotorolaIntegers && CurPtr[-1] == '%') {
532 const char *NumStart = CurPtr;
533 while (*CurPtr == '0' || *CurPtr == '1')
534 ++CurPtr;
535
536 APInt Result(128, 0);
537 if (StringRef(NumStart, CurPtr - NumStart).getAsInteger(2, Result))
538 return ReturnError(TokStart, "invalid binary number");
539
540 return intToken(StringRef(TokStart, CurPtr - TokStart), Result);
541 }
542
543
544
545
546
547 if (LexHLASMIntegers || CurPtr[-1] != '0' || CurPtr[0] == '.') {
548 unsigned Radix = doHexLookAhead(CurPtr, 10, LexMasmIntegers);
549
550 if (!LexHLASMIntegers) {
551 bool IsHex = Radix == 16;
552
553 if (!IsHex && (*CurPtr == '.' || *CurPtr == 'e' || *CurPtr == 'E')) {
554 if (*CurPtr == '.')
555 ++CurPtr;
556 return LexFloatLiteral();
557 }
558 }
559
560 StringRef Result(TokStart, CurPtr - TokStart);
561
562 APInt Value(128, 0, true);
564 return ReturnError(TokStart, "invalid " + radixName(Radix) + " number");
565
566 if (!LexHLASMIntegers)
567
568
570
572 }
573
574 if (!LexMasmIntegers && ((*CurPtr == 'b') || (*CurPtr == 'B'))) {
575 ++CurPtr;
576
577 if ((CurPtr[0])) {
578 --CurPtr;
579 StringRef Result(TokStart, CurPtr - TokStart);
581 }
582 const char *NumStart = CurPtr;
583 while (CurPtr[0] == '0' || CurPtr[0] == '1')
584 ++CurPtr;
585
586
587 if (CurPtr == NumStart)
588 return ReturnError(TokStart, "invalid binary number");
589
590 StringRef Result(TokStart, CurPtr - TokStart);
591
592 APInt Value(128, 0, true);
593 if (Result.substr(2).getAsInteger(2, Value))
594 return ReturnError(TokStart, "invalid binary number");
595
596
597
599
601 }
602
603 if ((*CurPtr == 'x') || (*CurPtr == 'X')) {
604 ++CurPtr;
605 const char *NumStart = CurPtr;
607 ++CurPtr;
608
609
610
611 if (CurPtr[0] == '.' || CurPtr[0] == 'p' || CurPtr[0] == 'P')
612 return LexHexFloatLiteral(NumStart == CurPtr);
613
614
615 if (CurPtr == NumStart)
616 return ReturnError(CurPtr-2, "invalid hexadecimal number");
617
618 APInt Result(128, 0);
619 if (StringRef(TokStart, CurPtr - TokStart).getAsInteger(0, Result))
620 return ReturnError(TokStart, "invalid hexadecimal number");
621
622
623 if (LexMasmIntegers && (*CurPtr == 'h' || *CurPtr == 'H'))
624 ++CurPtr;
625
626
627
629
630 return intToken(StringRef(TokStart, CurPtr - TokStart), Result);
631 }
632
633
634 APInt Value(128, 0, true);
635 unsigned Radix = doHexLookAhead(CurPtr, 8, LexMasmIntegers);
636 StringRef Result(TokStart, CurPtr - TokStart);
638 return ReturnError(TokStart, "invalid " + radixName(Radix) + " number");
639
640
641 if (Radix == 16)
642 ++CurPtr;
643
644
645
647
649}
650
651
652AsmToken AsmLexer::LexSingleQuote() {
653 int CurChar = getNextChar();
654
655 if (LexHLASMStrings)
656 return ReturnError(TokStart, "invalid usage of character literals");
657
658 if (LexMasmStrings) {
659 while (CurChar != EOF) {
660 if (CurChar != '\'') {
661 CurChar = getNextChar();
662 } else if (peekNextChar() == '\'') {
663
664
665 (void)getNextChar();
666 CurChar = getNextChar();
667 } else {
668 break;
669 }
670 }
671 if (CurChar == EOF)
672 return ReturnError(TokStart, "unterminated string constant");
673 return AsmToken(AsmToken::String, StringRef(TokStart, CurPtr - TokStart));
674 }
675
676 if (CurChar == '\\')
677 CurChar = getNextChar();
678
679 if (CurChar == EOF)
680 return ReturnError(TokStart, "unterminated single quote");
681
682 CurChar = getNextChar();
683
684 if (CurChar != '\'')
685 return ReturnError(TokStart, "single quote way too long");
686
687
688
689 StringRef Res = StringRef(TokStart,CurPtr - TokStart);
691
693 char theChar = Res[2];
694 switch (theChar) {
695 default: Value = theChar; break;
696 case '\'': Value = '\''; break;
697 case 't': Value = '\t'; break;
698 case 'n': Value = '\n'; break;
699 case 'b': Value = '\b'; break;
700 case 'f': Value = '\f'; break;
701 case 'r': Value = '\r'; break;
702 }
703 } else
704 Value = TokStart[1];
705
707}
708
709
710AsmToken AsmLexer::LexQuote() {
711 int CurChar = getNextChar();
712 if (LexHLASMStrings)
713 return ReturnError(TokStart, "invalid usage of string literals");
714
715 if (LexMasmStrings) {
716 while (CurChar != EOF) {
717 if (CurChar != '"') {
718 CurChar = getNextChar();
719 } else if (peekNextChar() == '"') {
720
721
722 (void)getNextChar();
723 CurChar = getNextChar();
724 } else {
725 break;
726 }
727 }
728 if (CurChar == EOF)
729 return ReturnError(TokStart, "unterminated string constant");
730 return AsmToken(AsmToken::String, StringRef(TokStart, CurPtr - TokStart));
731 }
732
733 while (CurChar != '"') {
734 if (CurChar == '\\') {
735
736 CurChar = getNextChar();
737 }
738
739 if (CurChar == EOF)
740 return ReturnError(TokStart, "unterminated string constant");
741
742 CurChar = getNextChar();
743 }
744
745 return AsmToken(AsmToken::String, StringRef(TokStart, CurPtr - TokStart));
746}
747
749 TokStart = CurPtr;
750
751 while (!isAtStartOfComment(CurPtr) &&
752 !isAtStatementSeparator(CurPtr) &&
753 *CurPtr != '\n' && *CurPtr != '\r' && CurPtr != CurBuf.end()) {
754 ++CurPtr;
755 }
756 return StringRef(TokStart, CurPtr-TokStart);
757}
758
759StringRef AsmLexer::LexUntilEndOfLine() {
760 TokStart = CurPtr;
761
762 while (*CurPtr != '\n' && *CurPtr != '\r' && CurPtr != CurBuf.end()) {
763 ++CurPtr;
764 }
765 return StringRef(TokStart, CurPtr-TokStart);
766}
767
769 bool ShouldSkipSpace) {
773 SaveAndRestore SavedAtStartOfStatement(IsAtStartOfStatement);
774 SaveAndRestore SavedSkipSpace(SkipSpace, ShouldSkipSpace);
776 std::string SavedErr = getErr();
778
779 size_t ReadCount;
780 for (ReadCount = 0; ReadCount < Buf.size(); ++ReadCount) {
782
783 Buf[ReadCount] = Token;
784
786 ReadCount++;
787 break;
788 }
789 }
790
791 SetError(SavedErrLoc, SavedErr);
792 return ReadCount;
793}
794
795bool AsmLexer::isAtStartOfComment(const char *Ptr) {
796 if (MAI.isHLASM() && !IsAtStartOfStatement)
797 return false;
798
800
801 if (CommentString.size() == 1)
802 return CommentString[0] == Ptr[0];
803
804
805 if (CommentString[1] == '#')
806 return CommentString[0] == Ptr[0];
807
808 return strncmp(Ptr, CommentString.data(), CommentString.size()) == 0;
809}
810
811bool AsmLexer::isAtStatementSeparator(const char *Ptr) {
814}
815
816AsmToken AsmLexer::LexToken() {
817 TokStart = CurPtr;
818
819 int CurChar = getNextChar();
820
821 if (!IsPeeking && CurChar == '#' && IsAtStartOfStatement) {
822
823
824 AsmToken TokenBuf[2];
827
830 CurPtr = TokStart;
831 StringRef s = LexUntilEndOfLine();
832 UnLex(TokenBuf[1]);
833 UnLex(TokenBuf[0]);
835 }
836
837 if (MAI.shouldAllowAdditionalComments())
838 return LexLineComment();
839 }
840
841 if (isAtStartOfComment(TokStart)) {
842 StringRef CommentString = MAI.getCommentString();
843
844
845
846 if (CommentString.size() > 1 &&
847 StringRef(TokStart, CommentString.size()) == CommentString) {
848 CurPtr += CommentString.size() - 1;
849 }
850 return LexLineComment();
851 }
852
853 if (isAtStatementSeparator(TokStart)) {
854 CurPtr += strlen(MAI.getSeparatorString()) - 1;
855 IsAtStartOfLine = true;
856 IsAtStartOfStatement = true;
858 StringRef(TokStart, strlen(MAI.getSeparatorString())));
859 }
860
861
862
863 if (CurChar == EOF && !IsAtStartOfStatement && EndStatementAtEOF) {
864 IsAtStartOfLine = true;
865 IsAtStartOfStatement = true;
867 }
868 IsAtStartOfLine = false;
869 bool OldIsAtStartOfStatement = IsAtStartOfStatement;
870 IsAtStartOfStatement = false;
871 switch (CurChar) {
872 default:
873
874
875
876
877 if (isalpha(CurChar) || CurChar == '_' || CurChar == '.')
878 return LexIdentifier();
879
880
881 return ReturnError(TokStart, "invalid character in input");
882 case EOF:
883 if (EndStatementAtEOF) {
884 IsAtStartOfLine = true;
885 IsAtStartOfStatement = true;
886 }
887 return AsmToken(AsmToken::Eof, StringRef(TokStart, 0));
888 case 0:
889 case ' ':
890 case '\t':
891 IsAtStartOfStatement = OldIsAtStartOfStatement;
892 while (*CurPtr == ' ' || *CurPtr == '\t')
893 CurPtr++;
894 if (SkipSpace)
895 return LexToken();
896 else
897 return AsmToken(AsmToken::Space, StringRef(TokStart, CurPtr - TokStart));
898 case '\r': {
899 IsAtStartOfLine = true;
900 IsAtStartOfStatement = true;
901
902 if (CurPtr != CurBuf.end() && *CurPtr == '\n')
903 ++CurPtr;
905 StringRef(TokStart, CurPtr - TokStart));
906 }
907 case '\n':
908 IsAtStartOfLine = true;
909 IsAtStartOfStatement = true;
911 case ':': return AsmToken(AsmToken::Colon, StringRef(TokStart, 1));
912 case '+': return AsmToken(AsmToken::Plus, StringRef(TokStart, 1));
913 case '~': return AsmToken(AsmToken::Tilde, StringRef(TokStart, 1));
914 case '(': return AsmToken(AsmToken::LParen, StringRef(TokStart, 1));
915 case ')': return AsmToken(AsmToken::RParen, StringRef(TokStart, 1));
916 case '[': return AsmToken(AsmToken::LBrac, StringRef(TokStart, 1));
917 case ']': return AsmToken(AsmToken::RBrac, StringRef(TokStart, 1));
918 case '{': return AsmToken(AsmToken::LCurly, StringRef(TokStart, 1));
919 case '}': return AsmToken(AsmToken::RCurly, StringRef(TokStart, 1));
920 case '*': return AsmToken(AsmToken::Star, StringRef(TokStart, 1));
921 case ',': return AsmToken(AsmToken::Comma, StringRef(TokStart, 1));
922 case '$': {
923 if (LexMotorolaIntegers && isHexDigit(*CurPtr))
924 return LexDigit();
925 if (MAI.doesAllowDollarAtStartOfIdentifier())
926 return LexIdentifier();
928 }
929 case '@':
930 if (MAI.doesAllowAtAtStartOfIdentifier())
931 return LexIdentifier();
932 return AsmToken(AsmToken::At, StringRef(TokStart, 1));
933 case '#':
934 if (MAI.isHLASM())
935 return LexIdentifier();
936 return AsmToken(AsmToken::Hash, StringRef(TokStart, 1));
937 case '?':
938 if (MAI.doesAllowQuestionAtStartOfIdentifier())
939 return LexIdentifier();
942 case '=':
943 if (*CurPtr == '=') {
944 ++CurPtr;
946 }
947 return AsmToken(AsmToken::Equal, StringRef(TokStart, 1));
948 case '-':
949 if (*CurPtr == '>') {
950 ++CurPtr;
952 }
953 return AsmToken(AsmToken::Minus, StringRef(TokStart, 1));
954 case '|':
955 if (*CurPtr == '|') {
956 ++CurPtr;
958 }
959 return AsmToken(AsmToken::Pipe, StringRef(TokStart, 1));
960 case '^': return AsmToken(AsmToken::Caret, StringRef(TokStart, 1));
961 case '&':
962 if (*CurPtr == '&') {
963 ++CurPtr;
965 }
966 return AsmToken(AsmToken::Amp, StringRef(TokStart, 1));
967 case '!':
968 if (*CurPtr == '=') {
969 ++CurPtr;
971 }
973 case '%':
974 if (LexMotorolaIntegers && (*CurPtr == '0' || *CurPtr == '1')) {
975 return LexDigit();
976 }
978 case '/':
979 IsAtStartOfStatement = OldIsAtStartOfStatement;
980 return LexSlash();
981 case '\'': return LexSingleQuote();
982 case '"': return LexQuote();
983 case '0': case '1': case '2': case '3': case '4':
984 case '5': case '6': case '7': case '8': case '9':
985 return LexDigit();
986 case '<':
987 switch (*CurPtr) {
988 case '<':
989 ++CurPtr;
991 case '=':
992 ++CurPtr;
994 case '>':
995 ++CurPtr;
997 default:
998 return AsmToken(AsmToken::Less, StringRef(TokStart, 1));
999 }
1000 case '>':
1001 switch (*CurPtr) {
1002 case '>':
1003 ++CurPtr;
1005 case '=':
1006 ++CurPtr;
1008 default:
1010 }
1011
1012
1013
1014
1015
1016 }
1017}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file implements a class to represent arbitrary precision integral constant values and operations...
static std::string radixName(unsigned Radix)
Definition AsmLexer.cpp:387
static void SkipIgnoredIntegerSuffix(const char *&CurPtr)
Definition AsmLexer.cpp:337
static unsigned doHexLookAhead(const char *&CurPtr, unsigned DefaultRadix, bool LexHex)
Definition AsmLexer.cpp:349
static AsmToken intToken(StringRef Ref, APInt &Value)
Definition AsmLexer.cpp:381
static const char * findLastDigit(const char *CurPtr, unsigned DefaultRadix)
Definition AsmLexer.cpp:374
static bool isIdentifierChar(char C)
Return true if the given character satisfies the following regular expression: [-a-zA-Z$....
This file provides utility classes that use RAII to save and restore values.
Class for arbitrary precision integers.
size_t size() const
size - Get the array size.
LLVM_ABI AsmLexer(const MCAsmInfo &MAI)
Definition AsmLexer.cpp:110
void UnLex(AsmToken const &Token)
bool is(AsmToken::TokenKind K) const
Check if the current token has kind K.
SMLoc getErrLoc()
Get the current error location.
const std::string & getErr()
Get the current error string.
LLVM_ABI StringRef LexUntilEndOfStatement()
Definition AsmLexer.cpp:748
LLVM_ABI void setBuffer(StringRef Buf, const char *ptr=nullptr, bool EndStatementAtEOF=true)
Set buffer to be lexed.
Definition AsmLexer.cpp:120
LLVM_ABI size_t peekTokens(MutableArrayRef< AsmToken > Buf, bool ShouldSkipSpace=true)
Look ahead an arbitrary number of tokens.
Definition AsmLexer.cpp:768
Target independent representation for an assembler token.
LLVM_ABI SMLoc getLoc() const
Definition AsmLexer.cpp:31
StringRef getString() const
Get the string for the current token, this includes all characters (for example, the quotes on string...
bool is(TokenKind K) const
LLVM_ABI SMLoc getEndLoc() const
Definition AsmLexer.cpp:33
LLVM_ABI void dump(raw_ostream &OS) const
Definition AsmLexer.cpp:39
LLVM_ABI SMRange getLocRange() const
Definition AsmLexer.cpp:37
This class is intended to be used as a base class for asm properties and features specific to the tar...
StringRef getCommentString() const
const char * getSeparatorString() const
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Represents a location in source code.
static SMLoc getFromPointer(const char *Ptr)
Represents a range in source code.
StringRef - Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
LLVM Value Representation.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & write_escaped(StringRef Str, bool UseHexEscapes=false)
Output Str, turning '\', '\t', ' ', '"', and anything that doesn't satisfy llvm::isPrint into an esca...
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
unsigned hexDigitValue(char C)
Interpret the given character C as a hexadecimal digit and return its value.
bool isDigit(char C)
Checks if character C is one of the 10 decimal digits.
bool isAlnum(char C)
Checks whether character C is either a decimal digit or an uppercase or lowercase letter as classifie...
MutableArrayRef(T &OneElt) -> MutableArrayRef< T >
@ Ref
The access may reference the value stored in memory.
bool isHexDigit(char C)
Checks if character C is a hexadecimal numeric character.
A utility class that uses RAII to save and restore the value of a variable.