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/LLVMContext.h"
18 #include "llvm/Support/MemoryBuffer.h"
19 #include "llvm/Support/MathExtras.h"
20 #include "llvm/Support/SourceMgr.h"
21 #include "llvm/Support/raw_ostream.h"
22 #include "llvm/Assembly/Parser.h"
27 bool LLLexer::Error(LocTy ErrorLoc, const std::string &Msg) const {
28 ErrorInfo = SM.GetMessage(ErrorLoc, Msg, "error");
32 //===----------------------------------------------------------------------===//
34 //===----------------------------------------------------------------------===//
36 // atoull - Convert an ascii string of decimal digits into the unsigned long
37 // long representation... this does not have to do input error checking,
38 // because we know that the input will be matched by a suitable regex...
40 uint64_t LLLexer::atoull(const char *Buffer, const char *End) {
42 for (; Buffer != End; Buffer++) {
43 uint64_t OldRes = Result;
45 Result += *Buffer-'0';
46 if (Result < OldRes) { // Uh, oh, overflow detected!!!
47 Error("constant bigger than 64 bits detected!");
54 uint64_t LLLexer::HexIntToVal(const char *Buffer, const char *End) {
56 for (; Buffer != End; ++Buffer) {
57 uint64_t OldRes = Result;
60 if (C >= '0' && C <= '9')
62 else if (C >= 'A' && C <= 'F')
64 else if (C >= 'a' && C <= 'f')
67 if (Result < OldRes) { // Uh, oh, overflow detected!!!
68 Error("constant bigger than 64 bits detected!");
75 void LLLexer::HexToIntPair(const char *Buffer, const char *End,
78 for (int i=0; i<16; i++, Buffer++) {
79 assert(Buffer != End);
82 if (C >= '0' && C <= '9')
84 else if (C >= 'A' && C <= 'F')
86 else if (C >= 'a' && C <= 'f')
90 for (int i=0; i<16 && Buffer != End; i++, Buffer++) {
93 if (C >= '0' && C <= '9')
95 else if (C >= 'A' && C <= 'F')
97 else if (C >= 'a' && C <= 'f')
101 Error("constant bigger than 128 bits detected!");
104 /// FP80HexToIntPair - translate an 80 bit FP80 number (20 hexits) into
105 /// { low64, high16 } as usual for an APInt.
106 void LLLexer::FP80HexToIntPair(const char *Buffer, const char *End,
109 for (int i=0; i<4 && Buffer != End; i++, Buffer++) {
110 assert(Buffer != End);
113 if (C >= '0' && C <= '9')
115 else if (C >= 'A' && C <= 'F')
117 else if (C >= 'a' && C <= 'f')
121 for (int i=0; i<16; i++, Buffer++) {
124 if (C >= '0' && C <= '9')
126 else if (C >= 'A' && C <= 'F')
128 else if (C >= 'a' && C <= 'f')
132 Error("constant bigger than 128 bits detected!");
135 // UnEscapeLexed - Run through the specified buffer and change \xx codes to the
136 // appropriate character.
137 static void UnEscapeLexed(std::string &Str) {
138 if (Str.empty()) return;
140 char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
142 for (char *BIn = Buffer; BIn != EndBuffer; ) {
143 if (BIn[0] == '\\') {
144 if (BIn < EndBuffer-1 && BIn[1] == '\\') {
145 *BOut++ = '\\'; // Two \ becomes one
147 } else if (BIn < EndBuffer-2 && isxdigit(BIn[1]) && isxdigit(BIn[2])) {
148 char Tmp = BIn[3]; BIn[3] = 0; // Terminate string
149 *BOut = (char)strtol(BIn+1, 0, 16); // Convert to number
150 BIn[3] = Tmp; // Restore character
151 BIn += 3; // Skip over handled chars
160 Str.resize(BOut-Buffer);
163 /// isLabelChar - Return true for [-a-zA-Z$._0-9].
164 static bool isLabelChar(char C) {
165 return isalnum(C) || C == '-' || C == '$' || C == '.' || C == '_';
169 /// isLabelTail - Return true if this pointer points to a valid end of a label.
170 static const char *isLabelTail(const char *CurPtr) {
172 if (CurPtr[0] == ':') return CurPtr+1;
173 if (!isLabelChar(CurPtr[0])) return 0;
180 //===----------------------------------------------------------------------===//
182 //===----------------------------------------------------------------------===//
184 LLLexer::LLLexer(MemoryBuffer *StartBuf, SourceMgr &sm, SMDiagnostic &Err,
186 : CurBuf(StartBuf), ErrorInfo(Err), SM(sm), Context(C), APFloatVal(0.0) {
187 CurPtr = CurBuf->getBufferStart();
190 std::string LLLexer::getFilename() const {
191 return CurBuf->getBufferIdentifier();
194 int LLLexer::getNextChar() {
195 char CurChar = *CurPtr++;
197 default: return (unsigned char)CurChar;
199 // A nul character in the stream is either the end of the current buffer or
200 // a random nul in the file. Disambiguate that here.
201 if (CurPtr-1 != CurBuf->getBufferEnd())
202 return 0; // Just whitespace.
204 // Otherwise, return end of file.
205 --CurPtr; // Another call to lex will return EOF again.
211 lltok::Kind LLLexer::LexToken() {
214 int CurChar = getNextChar();
217 // Handle letters: [a-zA-Z_]
218 if (isalpha(CurChar) || CurChar == '_')
219 return LexIdentifier();
222 case EOF: return lltok::Eof;
228 // Ignore whitespace.
230 case '+': return LexPositive();
231 case '@': return LexAt();
232 case '%': return LexPercent();
233 case '"': return LexQuote();
235 if (const char *Ptr = isLabelTail(CurPtr)) {
237 StrVal.assign(TokStart, CurPtr-1);
238 return lltok::LabelStr;
240 if (CurPtr[0] == '.' && CurPtr[1] == '.') {
242 return lltok::dotdotdot;
246 if (const char *Ptr = isLabelTail(CurPtr)) {
248 StrVal.assign(TokStart, CurPtr-1);
249 return lltok::LabelStr;
255 case '!': return lltok::Metadata;
256 case '0': case '1': case '2': case '3': case '4':
257 case '5': case '6': case '7': case '8': case '9':
259 return LexDigitOrNegative();
260 case '=': return lltok::equal;
261 case '[': return lltok::lsquare;
262 case ']': return lltok::rsquare;
263 case '{': return lltok::lbrace;
264 case '}': return lltok::rbrace;
265 case '<': return lltok::less;
266 case '>': return lltok::greater;
267 case '(': return lltok::lparen;
268 case ')': return lltok::rparen;
269 case ',': return lltok::comma;
270 case '*': return lltok::star;
271 case '\\': return lltok::backslash;
275 void LLLexer::SkipLineComment() {
277 if (CurPtr[0] == '\n' || CurPtr[0] == '\r' || getNextChar() == EOF)
282 /// LexAt - Lex all tokens that start with an @ character:
283 /// GlobalVar @\"[^\"]*\"
284 /// GlobalVar @[-a-zA-Z$._][-a-zA-Z$._0-9]*
285 /// GlobalVarID @[0-9]+
286 lltok::Kind LLLexer::LexAt() {
287 // Handle AtStringConstant: @\"[^\"]*\"
288 if (CurPtr[0] == '"') {
292 int CurChar = getNextChar();
294 if (CurChar == EOF) {
295 Error("end of file in global variable name");
298 if (CurChar == '"') {
299 StrVal.assign(TokStart+2, CurPtr-1);
300 UnEscapeLexed(StrVal);
301 return lltok::GlobalVar;
306 // Handle GlobalVarName: @[-a-zA-Z$._][-a-zA-Z$._0-9]*
307 if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
308 CurPtr[0] == '.' || CurPtr[0] == '_') {
310 while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
311 CurPtr[0] == '.' || CurPtr[0] == '_')
314 StrVal.assign(TokStart+1, CurPtr); // Skip @
315 return lltok::GlobalVar;
318 // Handle GlobalVarID: @[0-9]+
319 if (isdigit(CurPtr[0])) {
320 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
323 uint64_t Val = atoull(TokStart+1, CurPtr);
324 if ((unsigned)Val != Val)
325 Error("invalid value number (too large)!");
326 UIntVal = unsigned(Val);
327 return lltok::GlobalID;
334 /// LexPercent - Lex all tokens that start with a % character:
335 /// LocalVar ::= %\"[^\"]*\"
336 /// LocalVar ::= %[-a-zA-Z$._][-a-zA-Z$._0-9]*
337 /// LocalVarID ::= %[0-9]+
338 lltok::Kind LLLexer::LexPercent() {
339 // Handle LocalVarName: %\"[^\"]*\"
340 if (CurPtr[0] == '"') {
344 int CurChar = getNextChar();
346 if (CurChar == EOF) {
347 Error("end of file in string constant");
350 if (CurChar == '"') {
351 StrVal.assign(TokStart+2, CurPtr-1);
352 UnEscapeLexed(StrVal);
353 return lltok::LocalVar;
358 // Handle LocalVarName: %[-a-zA-Z$._][-a-zA-Z$._0-9]*
359 if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
360 CurPtr[0] == '.' || CurPtr[0] == '_') {
362 while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
363 CurPtr[0] == '.' || CurPtr[0] == '_')
366 StrVal.assign(TokStart+1, CurPtr); // Skip %
367 return lltok::LocalVar;
370 // Handle LocalVarID: %[0-9]+
371 if (isdigit(CurPtr[0])) {
372 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
375 uint64_t Val = atoull(TokStart+1, CurPtr);
376 if ((unsigned)Val != Val)
377 Error("invalid value number (too large)!");
378 UIntVal = unsigned(Val);
379 return lltok::LocalVarID;
385 /// LexQuote - Lex all tokens that start with a " character:
386 /// QuoteLabel "[^"]+":
387 /// StringConstant "[^"]*"
388 lltok::Kind LLLexer::LexQuote() {
390 int CurChar = getNextChar();
392 if (CurChar == EOF) {
393 Error("end of file in quoted string");
397 if (CurChar != '"') continue;
399 if (CurPtr[0] != ':') {
400 StrVal.assign(TokStart+1, CurPtr-1);
401 UnEscapeLexed(StrVal);
402 return lltok::StringConstant;
406 StrVal.assign(TokStart+1, CurPtr-2);
407 UnEscapeLexed(StrVal);
408 return lltok::LabelStr;
412 static bool JustWhitespaceNewLine(const char *&Ptr) {
413 const char *ThisPtr = Ptr;
414 while (*ThisPtr == ' ' || *ThisPtr == '\t')
416 if (*ThisPtr == '\n' || *ThisPtr == '\r') {
424 /// LexIdentifier: Handle several related productions:
425 /// Label [-a-zA-Z$._0-9]+:
426 /// IntegerType i[0-9]+
427 /// Keyword sdiv, float, ...
428 /// HexIntConstant [us]0x[0-9A-Fa-f]+
429 lltok::Kind LLLexer::LexIdentifier() {
430 const char *StartChar = CurPtr;
431 const char *IntEnd = CurPtr[-1] == 'i' ? 0 : StartChar;
432 const char *KeywordEnd = 0;
434 for (; isLabelChar(*CurPtr); ++CurPtr) {
435 // If we decide this is an integer, remember the end of the sequence.
436 if (!IntEnd && !isdigit(*CurPtr)) IntEnd = CurPtr;
437 if (!KeywordEnd && !isalnum(*CurPtr) && *CurPtr != '_') KeywordEnd = CurPtr;
440 // If we stopped due to a colon, this really is a label.
441 if (*CurPtr == ':') {
442 StrVal.assign(StartChar-1, CurPtr++);
443 return lltok::LabelStr;
446 // Otherwise, this wasn't a label. If this was valid as an integer type,
448 if (IntEnd == 0) IntEnd = CurPtr;
449 if (IntEnd != StartChar) {
451 uint64_t NumBits = atoull(StartChar, CurPtr);
452 if (NumBits < IntegerType::MIN_INT_BITS ||
453 NumBits > IntegerType::MAX_INT_BITS) {
454 Error("bitwidth for integer type out of range!");
457 TyVal = Context.getIntegerType(NumBits);
461 // Otherwise, this was a letter sequence. See which keyword this is.
462 if (KeywordEnd == 0) KeywordEnd = CurPtr;
465 unsigned Len = CurPtr-StartChar;
466 #define KEYWORD(STR) \
467 if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) \
468 return lltok::kw_##STR;
470 KEYWORD(begin); KEYWORD(end);
471 KEYWORD(true); KEYWORD(false);
472 KEYWORD(declare); KEYWORD(define);
473 KEYWORD(global); KEYWORD(constant);
477 KEYWORD(available_externally);
479 KEYWORD(linkonce_odr);
489 KEYWORD(extern_weak);
491 KEYWORD(thread_local);
492 KEYWORD(zeroinitializer);
514 KEYWORD(x86_stdcallcc);
515 KEYWORD(x86_fastcallcc);
517 KEYWORD(arm_aapcscc);
518 KEYWORD(arm_aapcs_vfpcc);
537 KEYWORD(alwaysinline);
542 KEYWORD(noimplicitfloat);
547 KEYWORD(eq); KEYWORD(ne); KEYWORD(slt); KEYWORD(sgt); KEYWORD(sle);
548 KEYWORD(sge); KEYWORD(ult); KEYWORD(ugt); KEYWORD(ule); KEYWORD(uge);
549 KEYWORD(oeq); KEYWORD(one); KEYWORD(olt); KEYWORD(ogt); KEYWORD(ole);
550 KEYWORD(oge); KEYWORD(ord); KEYWORD(uno); KEYWORD(ueq); KEYWORD(une);
555 // Keywords for types.
556 #define TYPEKEYWORD(STR, LLVMTY) \
557 if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
558 TyVal = LLVMTY; return lltok::Type; }
559 TYPEKEYWORD("void", Type::VoidTy);
560 TYPEKEYWORD("float", Type::FloatTy);
561 TYPEKEYWORD("double", Type::DoubleTy);
562 TYPEKEYWORD("x86_fp80", Type::X86_FP80Ty);
563 TYPEKEYWORD("fp128", Type::FP128Ty);
564 TYPEKEYWORD("ppc_fp128", Type::PPC_FP128Ty);
565 TYPEKEYWORD("label", Type::LabelTy);
566 TYPEKEYWORD("metadata", Type::MetadataTy);
569 // Handle special forms for autoupgrading. Drop these in LLVM 3.0. This is
570 // to avoid conflicting with the sext/zext instructions, below.
571 if (Len == 4 && !memcmp(StartChar, "sext", 4)) {
572 // Scan CurPtr ahead, seeing if there is just whitespace before the newline.
573 if (JustWhitespaceNewLine(CurPtr))
574 return lltok::kw_signext;
575 } else if (Len == 4 && !memcmp(StartChar, "zext", 4)) {
576 // Scan CurPtr ahead, seeing if there is just whitespace before the newline.
577 if (JustWhitespaceNewLine(CurPtr))
578 return lltok::kw_zeroext;
581 // Keywords for instructions.
582 #define INSTKEYWORD(STR, Enum) \
583 if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) { \
584 UIntVal = Instruction::Enum; return lltok::kw_##STR; }
586 INSTKEYWORD(add, Add); INSTKEYWORD(fadd, FAdd);
587 INSTKEYWORD(sub, Sub); INSTKEYWORD(fsub, FSub);
588 INSTKEYWORD(mul, Mul); INSTKEYWORD(fmul, FMul);
589 INSTKEYWORD(udiv, UDiv); INSTKEYWORD(sdiv, SDiv); INSTKEYWORD(fdiv, FDiv);
590 INSTKEYWORD(urem, URem); INSTKEYWORD(srem, SRem); INSTKEYWORD(frem, FRem);
591 INSTKEYWORD(shl, Shl); INSTKEYWORD(lshr, LShr); INSTKEYWORD(ashr, AShr);
592 INSTKEYWORD(and, And); INSTKEYWORD(or, Or); INSTKEYWORD(xor, Xor);
593 INSTKEYWORD(icmp, ICmp); INSTKEYWORD(fcmp, FCmp);
594 INSTKEYWORD(vicmp, VICmp); INSTKEYWORD(vfcmp, VFCmp);
596 INSTKEYWORD(phi, PHI);
597 INSTKEYWORD(call, Call);
598 INSTKEYWORD(trunc, Trunc);
599 INSTKEYWORD(zext, ZExt);
600 INSTKEYWORD(sext, SExt);
601 INSTKEYWORD(fptrunc, FPTrunc);
602 INSTKEYWORD(fpext, FPExt);
603 INSTKEYWORD(uitofp, UIToFP);
604 INSTKEYWORD(sitofp, SIToFP);
605 INSTKEYWORD(fptoui, FPToUI);
606 INSTKEYWORD(fptosi, FPToSI);
607 INSTKEYWORD(inttoptr, IntToPtr);
608 INSTKEYWORD(ptrtoint, PtrToInt);
609 INSTKEYWORD(bitcast, BitCast);
610 INSTKEYWORD(select, Select);
611 INSTKEYWORD(va_arg, VAArg);
612 INSTKEYWORD(ret, Ret);
614 INSTKEYWORD(switch, Switch);
615 INSTKEYWORD(invoke, Invoke);
616 INSTKEYWORD(unwind, Unwind);
617 INSTKEYWORD(unreachable, Unreachable);
619 INSTKEYWORD(malloc, Malloc);
620 INSTKEYWORD(alloca, Alloca);
621 INSTKEYWORD(free, Free);
622 INSTKEYWORD(load, Load);
623 INSTKEYWORD(store, Store);
624 INSTKEYWORD(getelementptr, GetElementPtr);
626 INSTKEYWORD(extractelement, ExtractElement);
627 INSTKEYWORD(insertelement, InsertElement);
628 INSTKEYWORD(shufflevector, ShuffleVector);
629 INSTKEYWORD(getresult, ExtractValue);
630 INSTKEYWORD(extractvalue, ExtractValue);
631 INSTKEYWORD(insertvalue, InsertValue);
634 // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
635 // the CFE to avoid forcing it to deal with 64-bit numbers.
636 if ((TokStart[0] == 'u' || TokStart[0] == 's') &&
637 TokStart[1] == '0' && TokStart[2] == 'x' && isxdigit(TokStart[3])) {
638 int len = CurPtr-TokStart-3;
639 uint32_t bits = len * 4;
640 APInt Tmp(bits, TokStart+3, len, 16);
641 uint32_t activeBits = Tmp.getActiveBits();
642 if (activeBits > 0 && activeBits < bits)
643 Tmp.trunc(activeBits);
644 APSIntVal = APSInt(Tmp, TokStart[0] == 'u');
645 return lltok::APSInt;
648 // If this is "cc1234", return this as just "cc".
649 if (TokStart[0] == 'c' && TokStart[1] == 'c') {
654 // If this starts with "call", return it as CALL. This is to support old
655 // broken .ll files. FIXME: remove this with LLVM 3.0.
656 if (CurPtr-TokStart > 4 && !memcmp(TokStart, "call", 4)) {
658 UIntVal = Instruction::Call;
659 return lltok::kw_call;
662 // Finally, if this isn't known, return an error.
668 /// Lex0x: Handle productions that start with 0x, knowing that it matches and
669 /// that this is not a label:
670 /// HexFPConstant 0x[0-9A-Fa-f]+
671 /// HexFP80Constant 0xK[0-9A-Fa-f]+
672 /// HexFP128Constant 0xL[0-9A-Fa-f]+
673 /// HexPPC128Constant 0xM[0-9A-Fa-f]+
674 lltok::Kind LLLexer::Lex0x() {
675 CurPtr = TokStart + 2;
678 if (CurPtr[0] >= 'K' && CurPtr[0] <= 'M') {
684 if (!isxdigit(CurPtr[0])) {
685 // Bad token, return it as an error.
690 while (isxdigit(CurPtr[0]))
694 // HexFPConstant - Floating point constant represented in IEEE format as a
695 // hexadecimal number for when exponential notation is not precise enough.
696 // Float and double only.
697 APFloatVal = APFloat(BitsToDouble(HexIntToVal(TokStart+2, CurPtr)));
698 return lltok::APFloat;
703 default: assert(0 && "Unknown kind!");
705 // F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
706 FP80HexToIntPair(TokStart+3, CurPtr, Pair);
707 APFloatVal = APFloat(APInt(80, 2, Pair));
708 return lltok::APFloat;
710 // F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
711 HexToIntPair(TokStart+3, CurPtr, Pair);
712 APFloatVal = APFloat(APInt(128, 2, Pair), true);
713 return lltok::APFloat;
715 // PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
716 HexToIntPair(TokStart+3, CurPtr, Pair);
717 APFloatVal = APFloat(APInt(128, 2, Pair));
718 return lltok::APFloat;
722 /// LexIdentifier: Handle several related productions:
723 /// Label [-a-zA-Z$._0-9]+:
725 /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
727 /// HexFPConstant 0x[0-9A-Fa-f]+
728 /// HexFP80Constant 0xK[0-9A-Fa-f]+
729 /// HexFP128Constant 0xL[0-9A-Fa-f]+
730 /// HexPPC128Constant 0xM[0-9A-Fa-f]+
731 lltok::Kind LLLexer::LexDigitOrNegative() {
732 // If the letter after the negative is a number, this is probably a label.
733 if (!isdigit(TokStart[0]) && !isdigit(CurPtr[0])) {
734 // Okay, this is not a number after the -, it's probably a label.
735 if (const char *End = isLabelTail(CurPtr)) {
736 StrVal.assign(TokStart, End-1);
738 return lltok::LabelStr;
744 // At this point, it is either a label, int or fp constant.
746 // Skip digits, we have at least one.
747 for (; isdigit(CurPtr[0]); ++CurPtr)
750 // Check to see if this really is a label afterall, e.g. "-1:".
751 if (isLabelChar(CurPtr[0]) || CurPtr[0] == ':') {
752 if (const char *End = isLabelTail(CurPtr)) {
753 StrVal.assign(TokStart, End-1);
755 return lltok::LabelStr;
759 // If the next character is a '.', then it is a fp value, otherwise its
761 if (CurPtr[0] != '.') {
762 if (TokStart[0] == '0' && TokStart[1] == 'x')
764 unsigned Len = CurPtr-TokStart;
765 uint32_t numBits = ((Len * 64) / 19) + 2;
766 APInt Tmp(numBits, TokStart, Len, 10);
767 if (TokStart[0] == '-') {
768 uint32_t minBits = Tmp.getMinSignedBits();
769 if (minBits > 0 && minBits < numBits)
771 APSIntVal = APSInt(Tmp, false);
773 uint32_t activeBits = Tmp.getActiveBits();
774 if (activeBits > 0 && activeBits < numBits)
775 Tmp.trunc(activeBits);
776 APSIntVal = APSInt(Tmp, true);
778 return lltok::APSInt;
783 // Skip over [0-9]*([eE][-+]?[0-9]+)?
784 while (isdigit(CurPtr[0])) ++CurPtr;
786 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
787 if (isdigit(CurPtr[1]) ||
788 ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
790 while (isdigit(CurPtr[0])) ++CurPtr;
794 APFloatVal = APFloat(atof(TokStart));
795 return lltok::APFloat;
798 /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
799 lltok::Kind LLLexer::LexPositive() {
800 // If the letter after the negative is a number, this is probably not a
802 if (!isdigit(CurPtr[0]))
806 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
809 // At this point, we need a '.'.
810 if (CurPtr[0] != '.') {
817 // Skip over [0-9]*([eE][-+]?[0-9]+)?
818 while (isdigit(CurPtr[0])) ++CurPtr;
820 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
821 if (isdigit(CurPtr[1]) ||
822 ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
824 while (isdigit(CurPtr[0])) ++CurPtr;
828 APFloatVal = APFloat(atof(TokStart));
829 return lltok::APFloat;