10
10
// ===----------------------------------------------------------------------===//
11
11
12
12
#include " LLLexer.h"
13
+ #include < llvm/ADT/APInt.h>
14
+ #include < llvm/ADT/STLExtras.h>
13
15
#include < llvm/ADT/StringExtras.h>
14
16
#include < llvm/ADT/Twine.h>
15
- #include < llvm/AsmParser/Parser.h>
16
17
#include < llvm/IR/DerivedTypes.h>
17
18
#include < llvm/IR/Instruction.h>
18
- #include < llvm/IR/LLVMContext.h>
19
19
#include < llvm/Support/ErrorHandling.h>
20
- #include < llvm/Support/MathExtras.h>
21
- #include < llvm/Support/MemoryBuffer.h>
22
20
#include < llvm/Support/SourceMgr.h>
23
- #include < llvm/Support/raw_ostream.h >
21
+ #include < cassert >
24
22
#include < cctype>
25
23
#include < cstdio>
26
- #include < cstdlib>
27
- #include < cstring>
24
+
28
25
using namespace llvm ;
29
26
30
27
bool LLLexer::Error (LocTy ErrorLoc, const Twine &Msg) const {
@@ -145,18 +142,15 @@ static bool isLabelChar(char C) {
145
142
C == ' .' || C == ' _' ;
146
143
}
147
144
148
-
149
145
// / isLabelTail - Return true if this pointer points to a valid end of a label.
150
146
static const char *isLabelTail (const char *CurPtr) {
151
- while (1 ) {
147
+ while (true ) {
152
148
if (CurPtr[0 ] == ' :' ) return CurPtr+1 ;
153
149
if (!isLabelChar (CurPtr[0 ])) return nullptr ;
154
150
++CurPtr;
155
151
}
156
152
}
157
153
158
-
159
-
160
154
// ===----------------------------------------------------------------------===//
161
155
// Lexer definition.
162
156
// ===----------------------------------------------------------------------===//
@@ -247,7 +241,7 @@ lltok::Kind LLLexer::LexToken() {
247
241
}
248
242
249
243
void LLLexer::SkipLineComment () {
250
- while (1 ) {
244
+ while (true ) {
251
245
if (CurPtr[0 ] == ' \n ' || CurPtr[0 ] == ' \r ' || getNextChar () == EOF)
252
246
return ;
253
247
}
@@ -272,7 +266,7 @@ lltok::Kind LLLexer::LexDollar() {
272
266
if (CurPtr[0 ] == ' "' ) {
273
267
++CurPtr;
274
268
275
- while (1 ) {
269
+ while (true ) {
276
270
int CurChar = getNextChar ();
277
271
278
272
if (CurChar == EOF) {
@@ -301,7 +295,7 @@ lltok::Kind LLLexer::LexDollar() {
301
295
// / ReadString - Read a string until the closing quote.
302
296
lltok::Kind LLLexer::ReadString (lltok::Kind kind) {
303
297
const char *Start = CurPtr;
304
- while (1 ) {
298
+ while (true ) {
305
299
int CurChar = getNextChar ();
306
300
307
301
if (CurChar == EOF) {
@@ -339,7 +333,7 @@ lltok::Kind LLLexer::LexVar(lltok::Kind Var, lltok::Kind VarID) {
339
333
if (CurPtr[0 ] == ' "' ) {
340
334
++CurPtr;
341
335
342
- while (1 ) {
336
+ while (true ) {
343
337
int CurChar = getNextChar ();
344
338
345
339
if (CurChar == EOF) {
@@ -489,11 +483,12 @@ lltok::Kind LLLexer::LexIdentifier() {
489
483
CurPtr = KeywordEnd;
490
484
--StartChar;
491
485
StringRef Keyword (StartChar, CurPtr - StartChar);
486
+
492
487
#define KEYWORD (STR ) \
493
488
do { \
494
489
if (Keyword == #STR) \
495
490
return lltok::kw_##STR; \
496
- } while (0 )
491
+ } while (false )
497
492
498
493
KEYWORD (true ); KEYWORD (false );
499
494
KEYWORD (declare); KEYWORD (define);
@@ -514,6 +509,7 @@ lltok::Kind LLLexer::LexIdentifier() {
514
509
KEYWORD (hidden);
515
510
KEYWORD (protected);
516
511
KEYWORD (unnamed_addr);
512
+ KEYWORD (local_unnamed_addr);
517
513
KEYWORD (externally_initialized);
518
514
KEYWORD (extern_weak);
519
515
KEYWORD (external);
@@ -534,6 +530,7 @@ lltok::Kind LLLexer::LexIdentifier() {
534
530
KEYWORD (notail);
535
531
KEYWORD (target);
536
532
KEYWORD (triple);
533
+ KEYWORD (source_filename);
537
534
KEYWORD (unwind);
538
535
KEYWORD (deplibs); // FIXME: Remove in 4.0.
539
536
KEYWORD (datalayout);
@@ -556,10 +553,12 @@ lltok::Kind LLLexer::LexIdentifier() {
556
553
KEYWORD (nsw);
557
554
KEYWORD (exact);
558
555
KEYWORD (inbounds);
556
+ KEYWORD (inrange);
559
557
KEYWORD (align);
560
558
KEYWORD (addrspace);
561
559
KEYWORD (section);
562
560
KEYWORD (alias);
561
+ KEYWORD (ifunc);
563
562
KEYWORD (module);
564
563
KEYWORD (asm );
565
564
KEYWORD (sideeffect);
@@ -580,14 +579,18 @@ lltok::Kind LLLexer::LexIdentifier() {
580
579
KEYWORD (arm_aapcscc);
581
580
KEYWORD (arm_aapcs_vfpcc);
582
581
KEYWORD (msp430_intrcc);
582
+ KEYWORD (avr_intrcc);
583
+ KEYWORD (avr_signalcc);
583
584
KEYWORD (ptx_kernel);
584
585
KEYWORD (ptx_device);
585
586
KEYWORD (spir_kernel);
586
587
KEYWORD (spir_func);
587
588
KEYWORD (intel_ocl_bicc);
588
589
KEYWORD (x86_64_sysvcc);
589
590
KEYWORD (x86_64_win64cc);
591
+ KEYWORD (x86_regcallcc);
590
592
KEYWORD (webkit_jscc);
593
+ KEYWORD (swiftcc);
591
594
KEYWORD (anyregcc);
592
595
KEYWORD (preserve_mostcc);
593
596
KEYWORD (preserve_allcc);
@@ -596,13 +599,19 @@ lltok::Kind LLLexer::LexIdentifier() {
596
599
KEYWORD (hhvmcc);
597
600
KEYWORD (hhvm_ccc);
598
601
KEYWORD (cxx_fast_tlscc);
602
+ KEYWORD (amdgpu_vs);
603
+ KEYWORD (amdgpu_gs);
604
+ KEYWORD (amdgpu_ps);
605
+ KEYWORD (amdgpu_cs);
606
+ KEYWORD (amdgpu_kernel);
599
607
600
608
KEYWORD (cc);
601
609
KEYWORD (c);
602
610
603
611
KEYWORD (attributes);
604
612
605
613
KEYWORD (alwaysinline);
614
+ KEYWORD (allocsize);
606
615
KEYWORD (argmemonly);
607
616
KEYWORD (builtin);
608
617
KEYWORD (byval);
@@ -646,7 +655,10 @@ lltok::Kind LLLexer::LexIdentifier() {
646
655
KEYWORD (sanitize_address);
647
656
KEYWORD (sanitize_thread);
648
657
KEYWORD (sanitize_memory);
658
+ KEYWORD (swifterror);
659
+ KEYWORD (swiftself);
649
660
KEYWORD (uwtable);
661
+ KEYWORD (writeonly);
650
662
KEYWORD (zeroext);
651
663
652
664
KEYWORD (type);
@@ -683,6 +695,7 @@ lltok::Kind LLLexer::LexIdentifier() {
683
695
KEYWORD (cleanup);
684
696
KEYWORD (catch );
685
697
KEYWORD (filter);
698
+
686
699
#undef KEYWORD
687
700
688
701
// Keywords for types.
@@ -693,6 +706,7 @@ lltok::Kind LLLexer::LexIdentifier() {
693
706
return lltok::Type; \
694
707
} \
695
708
} while (false )
709
+
696
710
TYPEKEYWORD (" void" , Type::getVoidTy (Context));
697
711
TYPEKEYWORD (" half" , Type::getHalfTy (Context));
698
712
TYPEKEYWORD (" float" , Type::getFloatTy (Context));
@@ -704,6 +718,7 @@ lltok::Kind LLLexer::LexIdentifier() {
704
718
TYPEKEYWORD (" metadata" , Type::getMetadataTy (Context));
705
719
TYPEKEYWORD (" x86_mmx" , Type::getX86_MMXTy (Context));
706
720
TYPEKEYWORD (" token" , Type::getTokenTy (Context));
721
+
707
722
#undef TYPEKEYWORD
708
723
709
724
// Keywords for instructions.
@@ -768,6 +783,7 @@ lltok::Kind LLLexer::LexIdentifier() {
768
783
INSTKEYWORD (catchswitch, CatchSwitch);
769
784
INSTKEYWORD (catchpad, CatchPad);
770
785
INSTKEYWORD (cleanuppad, CleanupPad);
786
+
771
787
#undef INSTKEYWORD
772
788
773
789
#define DWKEYWORD (TYPE, TOKEN ) \
@@ -777,19 +793,33 @@ lltok::Kind LLLexer::LexIdentifier() {
777
793
return lltok::TOKEN; \
778
794
} \
779
795
} while (false )
796
+
780
797
DWKEYWORD (TAG, DwarfTag);
781
798
DWKEYWORD (ATE, DwarfAttEncoding);
782
799
DWKEYWORD (VIRTUALITY, DwarfVirtuality);
783
800
DWKEYWORD (LANG, DwarfLang);
801
+ DWKEYWORD (CC, DwarfCC);
784
802
DWKEYWORD (OP, DwarfOp);
785
803
DWKEYWORD (MACINFO, DwarfMacinfo);
804
+
786
805
#undef DWKEYWORD
787
806
788
807
if (Keyword.startswith (" DIFlag" )) {
789
808
StrVal.assign (Keyword.begin (), Keyword.end ());
790
809
return lltok::DIFlag;
791
810
}
792
811
812
+ if (Keyword.startswith (" CSK_" )) {
813
+ StrVal.assign (Keyword.begin (), Keyword.end ());
814
+ return lltok::ChecksumKind;
815
+ }
816
+
817
+ if (Keyword == " NoDebug" || Keyword == " FullDebug" ||
818
+ Keyword == " LineTablesOnly" ) {
819
+ StrVal.assign (Keyword.begin (), Keyword.end ());
820
+ return lltok::EmissionKind;
821
+ }
822
+
793
823
// Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
794
824
// the CFE to avoid forcing it to deal with 64-bit numbers.
795
825
if ((TokStart[0 ] == ' u' || TokStart[0 ] == ' s' ) &&
@@ -798,7 +828,7 @@ lltok::Kind LLLexer::LexIdentifier() {
798
828
int len = CurPtr-TokStart-3 ;
799
829
uint32_t bits = len * 4 ;
800
830
StringRef HexStr (TokStart + 3 , len);
801
- if (!std:: all_of (HexStr. begin (), HexStr. end () , isxdigit)) {
831
+ if (!all_of (HexStr, isxdigit)) {
802
832
// Bad token, return it as an error.
803
833
CurPtr = TokStart+3 ;
804
834
return lltok::Error;
@@ -852,7 +882,8 @@ lltok::Kind LLLexer::Lex0x() {
852
882
// HexFPConstant - Floating point constant represented in IEEE format as a
853
883
// hexadecimal number for when exponential notation is not precise enough.
854
884
// Half, Float, and double only.
855
- APFloatVal = APFloat (BitsToDouble (HexIntToVal (TokStart+2 , CurPtr)));
885
+ APFloatVal = APFloat (APFloat::IEEEdouble (),
886
+ APInt (64 , HexIntToVal (TokStart + 2 , CurPtr)));
856
887
return lltok::APFloat;
857
888
}
858
889
@@ -862,20 +893,20 @@ lltok::Kind LLLexer::Lex0x() {
862
893
case ' K' :
863
894
// F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
864
895
FP80HexToIntPair (TokStart+3 , CurPtr, Pair);
865
- APFloatVal = APFloat (APFloat::x87DoubleExtended, APInt (80 , Pair));
896
+ APFloatVal = APFloat (APFloat::x87DoubleExtended () , APInt (80 , Pair));
866
897
return lltok::APFloat;
867
898
case ' L' :
868
899
// F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
869
900
HexToIntPair (TokStart+3 , CurPtr, Pair);
870
- APFloatVal = APFloat (APFloat::IEEEquad, APInt (128 , Pair));
901
+ APFloatVal = APFloat (APFloat::IEEEquad () , APInt (128 , Pair));
871
902
return lltok::APFloat;
872
903
case ' M' :
873
904
// PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
874
905
HexToIntPair (TokStart+3 , CurPtr, Pair);
875
- APFloatVal = APFloat (APFloat::PPCDoubleDouble, APInt (128 , Pair));
906
+ APFloatVal = APFloat (APFloat::PPCDoubleDouble () , APInt (128 , Pair));
876
907
return lltok::APFloat;
877
908
case ' H' :
878
- APFloatVal = APFloat (APFloat::IEEEhalf,
909
+ APFloatVal = APFloat (APFloat::IEEEhalf () ,
879
910
APInt (16 ,HexIntToVal (TokStart+3 , CurPtr)));
880
911
return lltok::APFloat;
881
912
}
@@ -942,7 +973,8 @@ lltok::Kind LLLexer::LexDigitOrNegative() {
942
973
}
943
974
}
944
975
945
- APFloatVal = APFloat (std::atof (TokStart));
976
+ APFloatVal = APFloat (APFloat::IEEEdouble (),
977
+ StringRef (TokStart, CurPtr - TokStart));
946
978
return lltok::APFloat;
947
979
}
948
980
@@ -978,6 +1010,7 @@ lltok::Kind LLLexer::LexPositive() {
978
1010
}
979
1011
}
980
1012
981
- APFloatVal = APFloat (std::atof (TokStart));
1013
+ APFloatVal = APFloat (APFloat::IEEEdouble (),
1014
+ StringRef (TokStart, CurPtr - TokStart));
982
1015
return lltok::APFloat;
983
1016
}
0 commit comments