1 //===- LLLexer.cpp - Lexer for .ll Files ----------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Implement the Lexer for .ll files.
12 //===----------------------------------------------------------------------===//
15 #include "llvm/DerivedTypes.h"
16 #include "llvm/Instruction.h"
17 #include "llvm/Support/MemoryBuffer.h"
18 #include "llvm/Support/MathExtras.h"
19 #include "llvm/Support/raw_ostream.h"
20 #include "llvm/Assembly/Parser.h"
25 bool LLLexer::Error(LocTy ErrorLoc
, const std::string
&Msg
) const {
26 // Scan backward to find the start of the line.
27 const char *LineStart
= ErrorLoc
;
28 while (LineStart
!= CurBuf
->getBufferStart() &&
29 LineStart
[-1] != '\n' && LineStart
[-1] != '\r')
31 // Get the end of the line.
32 const char *LineEnd
= ErrorLoc
;
33 while (LineEnd
!= CurBuf
->getBufferEnd() &&
34 LineEnd
[0] != '\n' && LineEnd
[0] != '\r')
38 for (const char *FP
= CurBuf
->getBufferStart(); FP
!= ErrorLoc
; ++FP
)
39 if (*FP
== '\n') ++LineNo
;
41 std::string
LineContents(LineStart
, LineEnd
);
42 ErrorInfo
.setError(Msg
, LineNo
, ErrorLoc
-LineStart
, LineContents
);
46 //===----------------------------------------------------------------------===//
48 //===----------------------------------------------------------------------===//
50 // atoull - Convert an ascii string of decimal digits into the unsigned long
51 // long representation... this does not have to do input error checking,
52 // because we know that the input will be matched by a suitable regex...
54 uint64_t LLLexer::atoull(const char *Buffer
, const char *End
) {
56 for (; Buffer
!= End
; Buffer
++) {
57 uint64_t OldRes
= Result
;
59 Result
+= *Buffer
-'0';
60 if (Result
< OldRes
) { // Uh, oh, overflow detected!!!
61 Error("constant bigger than 64 bits detected!");
68 uint64_t LLLexer::HexIntToVal(const char *Buffer
, const char *End
) {
70 for (; Buffer
!= End
; ++Buffer
) {
71 uint64_t OldRes
= Result
;
74 if (C
>= '0' && C
<= '9')
76 else if (C
>= 'A' && C
<= 'F')
78 else if (C
>= 'a' && C
<= 'f')
81 if (Result
< OldRes
) { // Uh, oh, overflow detected!!!
82 Error("constant bigger than 64 bits detected!");
89 void LLLexer::HexToIntPair(const char *Buffer
, const char *End
,
92 for (int i
=0; i
<16; i
++, Buffer
++) {
93 assert(Buffer
!= End
);
96 if (C
>= '0' && C
<= '9')
98 else if (C
>= 'A' && C
<= 'F')
100 else if (C
>= 'a' && C
<= 'f')
104 for (int i
=0; i
<16 && Buffer
!= End
; i
++, Buffer
++) {
107 if (C
>= '0' && C
<= '9')
109 else if (C
>= 'A' && C
<= 'F')
111 else if (C
>= 'a' && C
<= 'f')
115 Error("constant bigger than 128 bits detected!");
118 /// FP80HexToIntPair - translate an 80 bit FP80 number (20 hexits) into
119 /// { low64, high16 } as usual for an APInt.
120 void LLLexer::FP80HexToIntPair(const char *Buffer
, const char *End
,
123 for (int i
=0; i
<4 && Buffer
!= End
; i
++, Buffer
++) {
124 assert(Buffer
!= End
);
127 if (C
>= '0' && C
<= '9')
129 else if (C
>= 'A' && C
<= 'F')
131 else if (C
>= 'a' && C
<= 'f')
135 for (int i
=0; i
<16; i
++, Buffer
++) {
138 if (C
>= '0' && C
<= '9')
140 else if (C
>= 'A' && C
<= 'F')
142 else if (C
>= 'a' && C
<= 'f')
146 Error("constant bigger than 128 bits detected!");
149 // UnEscapeLexed - Run through the specified buffer and change \xx codes to the
150 // appropriate character.
151 static void UnEscapeLexed(std::string
&Str
) {
152 if (Str
.empty()) return;
154 char *Buffer
= &Str
[0], *EndBuffer
= Buffer
+Str
.size();
156 for (char *BIn
= Buffer
; BIn
!= EndBuffer
; ) {
157 if (BIn
[0] == '\\') {
158 if (BIn
< EndBuffer
-1 && BIn
[1] == '\\') {
159 *BOut
++ = '\\'; // Two \ becomes one
161 } else if (BIn
< EndBuffer
-2 && isxdigit(BIn
[1]) && isxdigit(BIn
[2])) {
162 char Tmp
= BIn
[3]; BIn
[3] = 0; // Terminate string
163 *BOut
= (char)strtol(BIn
+1, 0, 16); // Convert to number
164 BIn
[3] = Tmp
; // Restore character
165 BIn
+= 3; // Skip over handled chars
174 Str
.resize(BOut
-Buffer
);
177 /// isLabelChar - Return true for [-a-zA-Z$._0-9].
178 static bool isLabelChar(char C
) {
179 return isalnum(C
) || C
== '-' || C
== '$' || C
== '.' || C
== '_';
183 /// isLabelTail - Return true if this pointer points to a valid end of a label.
184 static const char *isLabelTail(const char *CurPtr
) {
186 if (CurPtr
[0] == ':') return CurPtr
+1;
187 if (!isLabelChar(CurPtr
[0])) return 0;
194 //===----------------------------------------------------------------------===//
196 //===----------------------------------------------------------------------===//
198 LLLexer::LLLexer(MemoryBuffer
*StartBuf
, ParseError
&Err
)
199 : CurBuf(StartBuf
), ErrorInfo(Err
), APFloatVal(0.0) {
200 CurPtr
= CurBuf
->getBufferStart();
203 std::string
LLLexer::getFilename() const {
204 return CurBuf
->getBufferIdentifier();
207 int LLLexer::getNextChar() {
208 char CurChar
= *CurPtr
++;
210 default: return (unsigned char)CurChar
;
212 // A nul character in the stream is either the end of the current buffer or
213 // a random nul in the file. Disambiguate that here.
214 if (CurPtr
-1 != CurBuf
->getBufferEnd())
215 return 0; // Just whitespace.
217 // Otherwise, return end of file.
218 --CurPtr
; // Another call to lex will return EOF again.
224 lltok::Kind
LLLexer::LexToken() {
227 int CurChar
= getNextChar();
230 // Handle letters: [a-zA-Z_]
231 if (isalpha(CurChar
) || CurChar
== '_')
232 return LexIdentifier();
235 case EOF
: return lltok::Eof
;
241 // Ignore whitespace.
243 case '+': return LexPositive();
244 case '@': return LexAt();
245 case '%': return LexPercent();
246 case '"': return LexQuote();
248 if (const char *Ptr
= isLabelTail(CurPtr
)) {
250 StrVal
.assign(TokStart
, CurPtr
-1);
251 return lltok::LabelStr
;
253 if (CurPtr
[0] == '.' && CurPtr
[1] == '.') {
255 return lltok::dotdotdot
;
259 if (const char *Ptr
= isLabelTail(CurPtr
)) {
261 StrVal
.assign(TokStart
, CurPtr
-1);
262 return lltok::LabelStr
;
268 case '!': return lltok::Metadata
;
269 case '0': case '1': case '2': case '3': case '4':
270 case '5': case '6': case '7': case '8': case '9':
272 return LexDigitOrNegative();
273 case '=': return lltok::equal
;
274 case '[': return lltok::lsquare
;
275 case ']': return lltok::rsquare
;
276 case '{': return lltok::lbrace
;
277 case '}': return lltok::rbrace
;
278 case '<': return lltok::less
;
279 case '>': return lltok::greater
;
280 case '(': return lltok::lparen
;
281 case ')': return lltok::rparen
;
282 case ',': return lltok::comma
;
283 case '*': return lltok::star
;
284 case '\\': return lltok::backslash
;
288 void LLLexer::SkipLineComment() {
290 if (CurPtr
[0] == '\n' || CurPtr
[0] == '\r' || getNextChar() == EOF
)
295 /// LexAt - Lex all tokens that start with an @ character:
296 /// GlobalVar @\"[^\"]*\"
297 /// GlobalVar @[-a-zA-Z$._][-a-zA-Z$._0-9]*
298 /// GlobalVarID @[0-9]+
299 lltok::Kind
LLLexer::LexAt() {
300 // Handle AtStringConstant: @\"[^\"]*\"
301 if (CurPtr
[0] == '"') {
305 int CurChar
= getNextChar();
307 if (CurChar
== EOF
) {
308 Error("end of file in global variable name");
311 if (CurChar
== '"') {
312 StrVal
.assign(TokStart
+2, CurPtr
-1);
313 UnEscapeLexed(StrVal
);
314 return lltok::GlobalVar
;
319 // Handle GlobalVarName: @[-a-zA-Z$._][-a-zA-Z$._0-9]*
320 if (isalpha(CurPtr
[0]) || CurPtr
[0] == '-' || CurPtr
[0] == '$' ||
321 CurPtr
[0] == '.' || CurPtr
[0] == '_') {
323 while (isalnum(CurPtr
[0]) || CurPtr
[0] == '-' || CurPtr
[0] == '$' ||
324 CurPtr
[0] == '.' || CurPtr
[0] == '_')
327 StrVal
.assign(TokStart
+1, CurPtr
); // Skip @
328 return lltok::GlobalVar
;
331 // Handle GlobalVarID: @[0-9]+
332 if (isdigit(CurPtr
[0])) {
333 for (++CurPtr
; isdigit(CurPtr
[0]); ++CurPtr
)
336 uint64_t Val
= atoull(TokStart
+1, CurPtr
);
337 if ((unsigned)Val
!= Val
)
338 Error("invalid value number (too large)!");
339 UIntVal
= unsigned(Val
);
340 return lltok::GlobalID
;
347 /// LexPercent - Lex all tokens that start with a % character:
348 /// LocalVar ::= %\"[^\"]*\"
349 /// LocalVar ::= %[-a-zA-Z$._][-a-zA-Z$._0-9]*
350 /// LocalVarID ::= %[0-9]+
351 lltok::Kind
LLLexer::LexPercent() {
352 // Handle LocalVarName: %\"[^\"]*\"
353 if (CurPtr
[0] == '"') {
357 int CurChar
= getNextChar();
359 if (CurChar
== EOF
) {
360 Error("end of file in string constant");
363 if (CurChar
== '"') {
364 StrVal
.assign(TokStart
+2, CurPtr
-1);
365 UnEscapeLexed(StrVal
);
366 return lltok::LocalVar
;
371 // Handle LocalVarName: %[-a-zA-Z$._][-a-zA-Z$._0-9]*
372 if (isalpha(CurPtr
[0]) || CurPtr
[0] == '-' || CurPtr
[0] == '$' ||
373 CurPtr
[0] == '.' || CurPtr
[0] == '_') {
375 while (isalnum(CurPtr
[0]) || CurPtr
[0] == '-' || CurPtr
[0] == '$' ||
376 CurPtr
[0] == '.' || CurPtr
[0] == '_')
379 StrVal
.assign(TokStart
+1, CurPtr
); // Skip %
380 return lltok::LocalVar
;
383 // Handle LocalVarID: %[0-9]+
384 if (isdigit(CurPtr
[0])) {
385 for (++CurPtr
; isdigit(CurPtr
[0]); ++CurPtr
)
388 uint64_t Val
= atoull(TokStart
+1, CurPtr
);
389 if ((unsigned)Val
!= Val
)
390 Error("invalid value number (too large)!");
391 UIntVal
= unsigned(Val
);
392 return lltok::LocalVarID
;
398 /// LexQuote - Lex all tokens that start with a " character:
399 /// QuoteLabel "[^"]+":
400 /// StringConstant "[^"]*"
401 lltok::Kind
LLLexer::LexQuote() {
403 int CurChar
= getNextChar();
405 if (CurChar
== EOF
) {
406 Error("end of file in quoted string");
410 if (CurChar
!= '"') continue;
412 if (CurPtr
[0] != ':') {
413 StrVal
.assign(TokStart
+1, CurPtr
-1);
414 UnEscapeLexed(StrVal
);
415 return lltok::StringConstant
;
419 StrVal
.assign(TokStart
+1, CurPtr
-2);
420 UnEscapeLexed(StrVal
);
421 return lltok::LabelStr
;
425 static bool JustWhitespaceNewLine(const char *&Ptr
) {
426 const char *ThisPtr
= Ptr
;
427 while (*ThisPtr
== ' ' || *ThisPtr
== '\t')
429 if (*ThisPtr
== '\n' || *ThisPtr
== '\r') {
437 /// LexIdentifier: Handle several related productions:
438 /// Label [-a-zA-Z$._0-9]+:
439 /// IntegerType i[0-9]+
440 /// Keyword sdiv, float, ...
441 /// HexIntConstant [us]0x[0-9A-Fa-f]+
442 lltok::Kind
LLLexer::LexIdentifier() {
443 const char *StartChar
= CurPtr
;
444 const char *IntEnd
= CurPtr
[-1] == 'i' ? 0 : StartChar
;
445 const char *KeywordEnd
= 0;
447 for (; isLabelChar(*CurPtr
); ++CurPtr
) {
448 // If we decide this is an integer, remember the end of the sequence.
449 if (!IntEnd
&& !isdigit(*CurPtr
)) IntEnd
= CurPtr
;
450 if (!KeywordEnd
&& !isalnum(*CurPtr
) && *CurPtr
!= '_') KeywordEnd
= CurPtr
;
453 // If we stopped due to a colon, this really is a label.
454 if (*CurPtr
== ':') {
455 StrVal
.assign(StartChar
-1, CurPtr
++);
456 return lltok::LabelStr
;
459 // Otherwise, this wasn't a label. If this was valid as an integer type,
461 if (IntEnd
== 0) IntEnd
= CurPtr
;
462 if (IntEnd
!= StartChar
) {
464 uint64_t NumBits
= atoull(StartChar
, CurPtr
);
465 if (NumBits
< IntegerType::MIN_INT_BITS
||
466 NumBits
> IntegerType::MAX_INT_BITS
) {
467 Error("bitwidth for integer type out of range!");
470 TyVal
= IntegerType::get(NumBits
);
474 // Otherwise, this was a letter sequence. See which keyword this is.
475 if (KeywordEnd
== 0) KeywordEnd
= CurPtr
;
478 unsigned Len
= CurPtr
-StartChar
;
479 #define KEYWORD(STR) \
480 if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) \
481 return lltok::kw_##STR;
483 KEYWORD(begin
); KEYWORD(end
);
484 KEYWORD(true); KEYWORD(false);
485 KEYWORD(declare
); KEYWORD(define
);
486 KEYWORD(global
); KEYWORD(constant
);
490 KEYWORD(available_externally
);
492 KEYWORD(linkonce_odr
);
502 KEYWORD(extern_weak
);
504 KEYWORD(thread_local
);
505 KEYWORD(zeroinitializer
);
527 KEYWORD(x86_stdcallcc
);
528 KEYWORD(x86_fastcallcc
);
546 KEYWORD(alwaysinline
);
554 KEYWORD(eq
); KEYWORD(ne
); KEYWORD(slt
); KEYWORD(sgt
); KEYWORD(sle
);
555 KEYWORD(sge
); KEYWORD(ult
); KEYWORD(ugt
); KEYWORD(ule
); KEYWORD(uge
);
556 KEYWORD(oeq
); KEYWORD(one
); KEYWORD(olt
); KEYWORD(ogt
); KEYWORD(ole
);
557 KEYWORD(oge
); KEYWORD(ord
); KEYWORD(uno
); KEYWORD(ueq
); KEYWORD(une
);
562 // Keywords for types.
563 #define TYPEKEYWORD(STR, LLVMTY) \
564 if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
565 TyVal = LLVMTY; return lltok::Type; }
566 TYPEKEYWORD("void", Type::VoidTy
);
567 TYPEKEYWORD("float", Type::FloatTy
);
568 TYPEKEYWORD("double", Type::DoubleTy
);
569 TYPEKEYWORD("x86_fp80", Type::X86_FP80Ty
);
570 TYPEKEYWORD("fp128", Type::FP128Ty
);
571 TYPEKEYWORD("ppc_fp128", Type::PPC_FP128Ty
);
572 TYPEKEYWORD("label", Type::LabelTy
);
575 // Handle special forms for autoupgrading. Drop these in LLVM 3.0. This is
576 // to avoid conflicting with the sext/zext instructions, below.
577 if (Len
== 4 && !memcmp(StartChar
, "sext", 4)) {
578 // Scan CurPtr ahead, seeing if there is just whitespace before the newline.
579 if (JustWhitespaceNewLine(CurPtr
))
580 return lltok::kw_signext
;
581 } else if (Len
== 4 && !memcmp(StartChar
, "zext", 4)) {
582 // Scan CurPtr ahead, seeing if there is just whitespace before the newline.
583 if (JustWhitespaceNewLine(CurPtr
))
584 return lltok::kw_zeroext
;
587 // Keywords for instructions.
588 #define INSTKEYWORD(STR, Enum) \
589 if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) { \
590 UIntVal = Instruction::Enum; return lltok::kw_##STR; }
592 INSTKEYWORD(add
, Add
); INSTKEYWORD(sub
, Sub
); INSTKEYWORD(mul
, Mul
);
593 INSTKEYWORD(udiv
, UDiv
); INSTKEYWORD(sdiv
, SDiv
); INSTKEYWORD(fdiv
, FDiv
);
594 INSTKEYWORD(urem
, URem
); INSTKEYWORD(srem
, SRem
); INSTKEYWORD(frem
, FRem
);
595 INSTKEYWORD(shl
, Shl
); INSTKEYWORD(lshr
, LShr
); INSTKEYWORD(ashr
, AShr
);
596 INSTKEYWORD(and, And
); INSTKEYWORD(or, Or
); INSTKEYWORD(xor, Xor
);
597 INSTKEYWORD(icmp
, ICmp
); INSTKEYWORD(fcmp
, FCmp
);
598 INSTKEYWORD(vicmp
, VICmp
); INSTKEYWORD(vfcmp
, VFCmp
);
600 INSTKEYWORD(phi
, PHI
);
601 INSTKEYWORD(call
, Call
);
602 INSTKEYWORD(trunc
, Trunc
);
603 INSTKEYWORD(zext
, ZExt
);
604 INSTKEYWORD(sext
, SExt
);
605 INSTKEYWORD(fptrunc
, FPTrunc
);
606 INSTKEYWORD(fpext
, FPExt
);
607 INSTKEYWORD(uitofp
, UIToFP
);
608 INSTKEYWORD(sitofp
, SIToFP
);
609 INSTKEYWORD(fptoui
, FPToUI
);
610 INSTKEYWORD(fptosi
, FPToSI
);
611 INSTKEYWORD(inttoptr
, IntToPtr
);
612 INSTKEYWORD(ptrtoint
, PtrToInt
);
613 INSTKEYWORD(bitcast
, BitCast
);
614 INSTKEYWORD(select
, Select
);
615 INSTKEYWORD(va_arg
, VAArg
);
616 INSTKEYWORD(ret
, Ret
);
618 INSTKEYWORD(switch, Switch
);
619 INSTKEYWORD(invoke
, Invoke
);
620 INSTKEYWORD(unwind
, Unwind
);
621 INSTKEYWORD(unreachable
, Unreachable
);
623 INSTKEYWORD(malloc
, Malloc
);
624 INSTKEYWORD(alloca
, Alloca
);
625 INSTKEYWORD(free
, Free
);
626 INSTKEYWORD(load
, Load
);
627 INSTKEYWORD(store
, Store
);
628 INSTKEYWORD(getelementptr
, GetElementPtr
);
630 INSTKEYWORD(extractelement
, ExtractElement
);
631 INSTKEYWORD(insertelement
, InsertElement
);
632 INSTKEYWORD(shufflevector
, ShuffleVector
);
633 INSTKEYWORD(getresult
, ExtractValue
);
634 INSTKEYWORD(extractvalue
, ExtractValue
);
635 INSTKEYWORD(insertvalue
, InsertValue
);
638 // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
639 // the CFE to avoid forcing it to deal with 64-bit numbers.
640 if ((TokStart
[0] == 'u' || TokStart
[0] == 's') &&
641 TokStart
[1] == '0' && TokStart
[2] == 'x' && isxdigit(TokStart
[3])) {
642 int len
= CurPtr
-TokStart
-3;
643 uint32_t bits
= len
* 4;
644 APInt
Tmp(bits
, TokStart
+3, len
, 16);
645 uint32_t activeBits
= Tmp
.getActiveBits();
646 if (activeBits
> 0 && activeBits
< bits
)
647 Tmp
.trunc(activeBits
);
648 APSIntVal
= APSInt(Tmp
, TokStart
[0] == 'u');
649 return lltok::APSInt
;
652 // If this is "cc1234", return this as just "cc".
653 if (TokStart
[0] == 'c' && TokStart
[1] == 'c') {
658 // If this starts with "call", return it as CALL. This is to support old
659 // broken .ll files. FIXME: remove this with LLVM 3.0.
660 if (CurPtr
-TokStart
> 4 && !memcmp(TokStart
, "call", 4)) {
662 UIntVal
= Instruction::Call
;
663 return lltok::kw_call
;
666 // Finally, if this isn't known, return an error.
672 /// Lex0x: Handle productions that start with 0x, knowing that it matches and
673 /// that this is not a label:
674 /// HexFPConstant 0x[0-9A-Fa-f]+
675 /// HexFP80Constant 0xK[0-9A-Fa-f]+
676 /// HexFP128Constant 0xL[0-9A-Fa-f]+
677 /// HexPPC128Constant 0xM[0-9A-Fa-f]+
678 lltok::Kind
LLLexer::Lex0x() {
679 CurPtr
= TokStart
+ 2;
682 if (CurPtr
[0] >= 'K' && CurPtr
[0] <= 'M') {
688 if (!isxdigit(CurPtr
[0])) {
689 // Bad token, return it as an error.
694 while (isxdigit(CurPtr
[0]))
698 // HexFPConstant - Floating point constant represented in IEEE format as a
699 // hexadecimal number for when exponential notation is not precise enough.
700 // Float and double only.
701 APFloatVal
= APFloat(BitsToDouble(HexIntToVal(TokStart
+2, CurPtr
)));
702 return lltok::APFloat
;
707 default: assert(0 && "Unknown kind!");
709 // F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
710 FP80HexToIntPair(TokStart
+3, CurPtr
, Pair
);
711 APFloatVal
= APFloat(APInt(80, 2, Pair
));
712 return lltok::APFloat
;
714 // F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
715 HexToIntPair(TokStart
+3, CurPtr
, Pair
);
716 APFloatVal
= APFloat(APInt(128, 2, Pair
), true);
717 return lltok::APFloat
;
719 // PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
720 HexToIntPair(TokStart
+3, CurPtr
, Pair
);
721 APFloatVal
= APFloat(APInt(128, 2, Pair
));
722 return lltok::APFloat
;
726 /// LexIdentifier: Handle several related productions:
727 /// Label [-a-zA-Z$._0-9]+:
729 /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
731 /// HexFPConstant 0x[0-9A-Fa-f]+
732 /// HexFP80Constant 0xK[0-9A-Fa-f]+
733 /// HexFP128Constant 0xL[0-9A-Fa-f]+
734 /// HexPPC128Constant 0xM[0-9A-Fa-f]+
735 lltok::Kind
LLLexer::LexDigitOrNegative() {
736 // If the letter after the negative is a number, this is probably a label.
737 if (!isdigit(TokStart
[0]) && !isdigit(CurPtr
[0])) {
738 // Okay, this is not a number after the -, it's probably a label.
739 if (const char *End
= isLabelTail(CurPtr
)) {
740 StrVal
.assign(TokStart
, End
-1);
742 return lltok::LabelStr
;
748 // At this point, it is either a label, int or fp constant.
750 // Skip digits, we have at least one.
751 for (; isdigit(CurPtr
[0]); ++CurPtr
)
754 // Check to see if this really is a label afterall, e.g. "-1:".
755 if (isLabelChar(CurPtr
[0]) || CurPtr
[0] == ':') {
756 if (const char *End
= isLabelTail(CurPtr
)) {
757 StrVal
.assign(TokStart
, End
-1);
759 return lltok::LabelStr
;
763 // If the next character is a '.', then it is a fp value, otherwise its
765 if (CurPtr
[0] != '.') {
766 if (TokStart
[0] == '0' && TokStart
[1] == 'x')
768 unsigned Len
= CurPtr
-TokStart
;
769 uint32_t numBits
= ((Len
* 64) / 19) + 2;
770 APInt
Tmp(numBits
, TokStart
, Len
, 10);
771 if (TokStart
[0] == '-') {
772 uint32_t minBits
= Tmp
.getMinSignedBits();
773 if (minBits
> 0 && minBits
< numBits
)
775 APSIntVal
= APSInt(Tmp
, false);
777 uint32_t activeBits
= Tmp
.getActiveBits();
778 if (activeBits
> 0 && activeBits
< numBits
)
779 Tmp
.trunc(activeBits
);
780 APSIntVal
= APSInt(Tmp
, true);
782 return lltok::APSInt
;
787 // Skip over [0-9]*([eE][-+]?[0-9]+)?
788 while (isdigit(CurPtr
[0])) ++CurPtr
;
790 if (CurPtr
[0] == 'e' || CurPtr
[0] == 'E') {
791 if (isdigit(CurPtr
[1]) ||
792 ((CurPtr
[1] == '-' || CurPtr
[1] == '+') && isdigit(CurPtr
[2]))) {
794 while (isdigit(CurPtr
[0])) ++CurPtr
;
798 APFloatVal
= APFloat(atof(TokStart
));
799 return lltok::APFloat
;
802 /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
803 lltok::Kind
LLLexer::LexPositive() {
804 // If the letter after the negative is a number, this is probably not a
806 if (!isdigit(CurPtr
[0]))
810 for (++CurPtr
; isdigit(CurPtr
[0]); ++CurPtr
)
813 // At this point, we need a '.'.
814 if (CurPtr
[0] != '.') {
821 // Skip over [0-9]*([eE][-+]?[0-9]+)?
822 while (isdigit(CurPtr
[0])) ++CurPtr
;
824 if (CurPtr
[0] == 'e' || CurPtr
[0] == 'E') {
825 if (isdigit(CurPtr
[1]) ||
826 ((CurPtr
[1] == '-' || CurPtr
[1] == '+') && isdigit(CurPtr
[2]))) {
828 while (isdigit(CurPtr
[0])) ++CurPtr
;
832 APFloatVal
= APFloat(atof(TokStart
));
833 return lltok::APFloat
;