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/ErrorHandling.h"
19 #include "llvm/Support/MemoryBuffer.h"
20 #include "llvm/Support/MathExtras.h"
21 #include "llvm/Support/SourceMgr.h"
22 #include "llvm/Support/raw_ostream.h"
23 #include "llvm/Assembly/Parser.h"
29 bool LLLexer::Error(LocTy ErrorLoc, const std::string &Msg) const {
30 ErrorInfo = SM.GetMessage(ErrorLoc, Msg, "error");
34 //===----------------------------------------------------------------------===//
36 //===----------------------------------------------------------------------===//
38 // atoull - Convert an ascii string of decimal digits into the unsigned long
39 // long representation... this does not have to do input error checking,
40 // because we know that the input will be matched by a suitable regex...
42 uint64_t LLLexer::atoull(const char *Buffer, const char *End) {
44 for (; Buffer != End; Buffer++) {
45 uint64_t OldRes = Result;
47 Result += *Buffer-'0';
48 if (Result < OldRes) { // Uh, oh, overflow detected!!!
49 Error("constant bigger than 64 bits detected!");
56 uint64_t LLLexer::HexIntToVal(const char *Buffer, const char *End) {
58 for (; Buffer != End; ++Buffer) {
59 uint64_t OldRes = Result;
62 if (C >= '0' && C <= '9')
64 else if (C >= 'A' && C <= 'F')
66 else if (C >= 'a' && C <= 'f')
69 if (Result < OldRes) { // Uh, oh, overflow detected!!!
70 Error("constant bigger than 64 bits detected!");
77 void LLLexer::HexToIntPair(const char *Buffer, const char *End,
80 for (int i=0; i<16; i++, Buffer++) {
81 assert(Buffer != End);
84 if (C >= '0' && C <= '9')
86 else if (C >= 'A' && C <= 'F')
88 else if (C >= 'a' && C <= 'f')
92 for (int i=0; i<16 && Buffer != End; i++, Buffer++) {
95 if (C >= '0' && C <= '9')
97 else if (C >= 'A' && C <= 'F')
99 else if (C >= 'a' && C <= 'f')
103 Error("constant bigger than 128 bits detected!");
106 /// FP80HexToIntPair - translate an 80 bit FP80 number (20 hexits) into
107 /// { low64, high16 } as usual for an APInt.
108 void LLLexer::FP80HexToIntPair(const char *Buffer, const char *End,
111 for (int i=0; i<4 && Buffer != End; i++, Buffer++) {
112 assert(Buffer != End);
115 if (C >= '0' && C <= '9')
117 else if (C >= 'A' && C <= 'F')
119 else if (C >= 'a' && C <= 'f')
123 for (int i=0; i<16; i++, Buffer++) {
126 if (C >= '0' && C <= '9')
128 else if (C >= 'A' && C <= 'F')
130 else if (C >= 'a' && C <= 'f')
134 Error("constant bigger than 128 bits detected!");
137 // UnEscapeLexed - Run through the specified buffer and change \xx codes to the
138 // appropriate character.
139 static void UnEscapeLexed(std::string &Str) {
140 if (Str.empty()) return;
142 char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
144 for (char *BIn = Buffer; BIn != EndBuffer; ) {
145 if (BIn[0] == '\\') {
146 if (BIn < EndBuffer-1 && BIn[1] == '\\') {
147 *BOut++ = '\\'; // Two \ becomes one
149 } else if (BIn < EndBuffer-2 && isxdigit(BIn[1]) && isxdigit(BIn[2])) {
150 char Tmp = BIn[3]; BIn[3] = 0; // Terminate string
151 *BOut = (char)strtol(BIn+1, 0, 16); // Convert to number
152 BIn[3] = Tmp; // Restore character
153 BIn += 3; // Skip over handled chars
162 Str.resize(BOut-Buffer);
165 /// isLabelChar - Return true for [-a-zA-Z$._0-9].
166 static bool isLabelChar(char C) {
167 return isalnum(C) || C == '-' || C == '$' || C == '.' || C == '_';
171 /// isLabelTail - Return true if this pointer points to a valid end of a label.
172 static const char *isLabelTail(const char *CurPtr) {
174 if (CurPtr[0] == ':') return CurPtr+1;
175 if (!isLabelChar(CurPtr[0])) return 0;
182 //===----------------------------------------------------------------------===//
184 //===----------------------------------------------------------------------===//
186 LLLexer::LLLexer(MemoryBuffer *StartBuf, SourceMgr &sm, SMDiagnostic &Err,
188 : CurBuf(StartBuf), ErrorInfo(Err), SM(sm), Context(C), APFloatVal(0.0) {
189 CurPtr = CurBuf->getBufferStart();
192 std::string LLLexer::getFilename() const {
193 return CurBuf->getBufferIdentifier();
196 int LLLexer::getNextChar() {
197 char CurChar = *CurPtr++;
199 default: return (unsigned char)CurChar;
201 // A nul character in the stream is either the end of the current buffer or
202 // a random nul in the file. Disambiguate that here.
203 if (CurPtr-1 != CurBuf->getBufferEnd())
204 return 0; // Just whitespace.
206 // Otherwise, return end of file.
207 --CurPtr; // Another call to lex will return EOF again.
213 lltok::Kind LLLexer::LexToken() {
216 int CurChar = getNextChar();
219 // Handle letters: [a-zA-Z_]
220 if (isalpha(CurChar) || CurChar == '_')
221 return LexIdentifier();
224 case EOF: return lltok::Eof;
230 // Ignore whitespace.
232 case '+': return LexPositive();
233 case '@': return LexAt();
234 case '%': return LexPercent();
235 case '"': return LexQuote();
237 if (const char *Ptr = isLabelTail(CurPtr)) {
239 StrVal.assign(TokStart, CurPtr-1);
240 return lltok::LabelStr;
242 if (CurPtr[0] == '.' && CurPtr[1] == '.') {
244 return lltok::dotdotdot;
248 if (const char *Ptr = isLabelTail(CurPtr)) {
250 StrVal.assign(TokStart, CurPtr-1);
251 return lltok::LabelStr;
257 case '!': return LexExclaim();
258 case '0': case '1': case '2': case '3': case '4':
259 case '5': case '6': case '7': case '8': case '9':
261 return LexDigitOrNegative();
262 case '=': return lltok::equal;
263 case '[': return lltok::lsquare;
264 case ']': return lltok::rsquare;
265 case '{': return lltok::lbrace;
266 case '}': return lltok::rbrace;
267 case '<': return lltok::less;
268 case '>': return lltok::greater;
269 case '(': return lltok::lparen;
270 case ')': return lltok::rparen;
271 case ',': return lltok::comma;
272 case '*': return lltok::star;
273 case '\\': return lltok::backslash;
277 void LLLexer::SkipLineComment() {
279 if (CurPtr[0] == '\n' || CurPtr[0] == '\r' || getNextChar() == EOF)
284 /// LexAt - Lex all tokens that start with an @ character:
285 /// GlobalVar @\"[^\"]*\"
286 /// GlobalVar @[-a-zA-Z$._][-a-zA-Z$._0-9]*
287 /// GlobalVarID @[0-9]+
288 lltok::Kind LLLexer::LexAt() {
289 // Handle AtStringConstant: @\"[^\"]*\"
290 if (CurPtr[0] == '"') {
294 int CurChar = getNextChar();
296 if (CurChar == EOF) {
297 Error("end of file in global variable name");
300 if (CurChar == '"') {
301 StrVal.assign(TokStart+2, CurPtr-1);
302 UnEscapeLexed(StrVal);
303 return lltok::GlobalVar;
308 // Handle GlobalVarName: @[-a-zA-Z$._][-a-zA-Z$._0-9]*
309 if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
310 CurPtr[0] == '.' || CurPtr[0] == '_') {
312 while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
313 CurPtr[0] == '.' || CurPtr[0] == '_')
316 StrVal.assign(TokStart+1, CurPtr); // Skip @
317 return lltok::GlobalVar;
320 // Handle GlobalVarID: @[0-9]+
321 if (isdigit(CurPtr[0])) {
322 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
325 uint64_t Val = atoull(TokStart+1, CurPtr);
326 if ((unsigned)Val != Val)
327 Error("invalid value number (too large)!");
328 UIntVal = unsigned(Val);
329 return lltok::GlobalID;
336 /// LexPercent - Lex all tokens that start with a % character:
337 /// LocalVar ::= %\"[^\"]*\"
338 /// LocalVar ::= %[-a-zA-Z$._][-a-zA-Z$._0-9]*
339 /// LocalVarID ::= %[0-9]+
340 lltok::Kind LLLexer::LexPercent() {
341 // Handle LocalVarName: %\"[^\"]*\"
342 if (CurPtr[0] == '"') {
346 int CurChar = getNextChar();
348 if (CurChar == EOF) {
349 Error("end of file in string constant");
352 if (CurChar == '"') {
353 StrVal.assign(TokStart+2, CurPtr-1);
354 UnEscapeLexed(StrVal);
355 return lltok::LocalVar;
360 // Handle LocalVarName: %[-a-zA-Z$._][-a-zA-Z$._0-9]*
361 if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
362 CurPtr[0] == '.' || CurPtr[0] == '_') {
364 while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
365 CurPtr[0] == '.' || CurPtr[0] == '_')
368 StrVal.assign(TokStart+1, CurPtr); // Skip %
369 return lltok::LocalVar;
372 // Handle LocalVarID: %[0-9]+
373 if (isdigit(CurPtr[0])) {
374 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
377 uint64_t Val = atoull(TokStart+1, CurPtr);
378 if ((unsigned)Val != Val)
379 Error("invalid value number (too large)!");
380 UIntVal = unsigned(Val);
381 return lltok::LocalVarID;
387 /// LexQuote - Lex all tokens that start with a " character:
388 /// QuoteLabel "[^"]+":
389 /// StringConstant "[^"]*"
390 lltok::Kind LLLexer::LexQuote() {
392 int CurChar = getNextChar();
394 if (CurChar == EOF) {
395 Error("end of file in quoted string");
399 if (CurChar != '"') continue;
401 if (CurPtr[0] != ':') {
402 StrVal.assign(TokStart+1, CurPtr-1);
403 UnEscapeLexed(StrVal);
404 return lltok::StringConstant;
408 StrVal.assign(TokStart+1, CurPtr-2);
409 UnEscapeLexed(StrVal);
410 return lltok::LabelStr;
414 static bool JustWhitespaceNewLine(const char *&Ptr) {
415 const char *ThisPtr = Ptr;
416 while (*ThisPtr == ' ' || *ThisPtr == '\t')
418 if (*ThisPtr == '\n' || *ThisPtr == '\r') {
428 lltok::Kind LLLexer::LexExclaim() {
429 // Lex a metadata name as a MetadataVar.
430 if (isalpha(CurPtr[0])) {
432 while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
433 CurPtr[0] == '.' || CurPtr[0] == '_')
436 StrVal.assign(TokStart+1, CurPtr); // Skip !
437 return lltok::MetadataVar;
439 return lltok::exclaim;
442 /// LexIdentifier: Handle several related productions:
443 /// Label [-a-zA-Z$._0-9]+:
444 /// IntegerType i[0-9]+
445 /// Keyword sdiv, float, ...
446 /// HexIntConstant [us]0x[0-9A-Fa-f]+
447 lltok::Kind LLLexer::LexIdentifier() {
448 const char *StartChar = CurPtr;
449 const char *IntEnd = CurPtr[-1] == 'i' ? 0 : StartChar;
450 const char *KeywordEnd = 0;
452 for (; isLabelChar(*CurPtr); ++CurPtr) {
453 // If we decide this is an integer, remember the end of the sequence.
454 if (!IntEnd && !isdigit(*CurPtr)) IntEnd = CurPtr;
455 if (!KeywordEnd && !isalnum(*CurPtr) && *CurPtr != '_') KeywordEnd = CurPtr;
458 // If we stopped due to a colon, this really is a label.
459 if (*CurPtr == ':') {
460 StrVal.assign(StartChar-1, CurPtr++);
461 return lltok::LabelStr;
464 // Otherwise, this wasn't a label. If this was valid as an integer type,
466 if (IntEnd == 0) IntEnd = CurPtr;
467 if (IntEnd != StartChar) {
469 uint64_t NumBits = atoull(StartChar, CurPtr);
470 if (NumBits < IntegerType::MIN_INT_BITS ||
471 NumBits > IntegerType::MAX_INT_BITS) {
472 Error("bitwidth for integer type out of range!");
475 TyVal = IntegerType::get(Context, NumBits);
479 // Otherwise, this was a letter sequence. See which keyword this is.
480 if (KeywordEnd == 0) KeywordEnd = CurPtr;
483 unsigned Len = CurPtr-StartChar;
484 #define KEYWORD(STR) \
485 if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) \
486 return lltok::kw_##STR;
488 KEYWORD(begin); KEYWORD(end);
489 KEYWORD(true); KEYWORD(false);
490 KEYWORD(declare); KEYWORD(define);
491 KEYWORD(global); KEYWORD(constant);
494 KEYWORD(linker_private);
496 KEYWORD(available_externally);
498 KEYWORD(linkonce_odr);
508 KEYWORD(extern_weak);
510 KEYWORD(thread_local);
511 KEYWORD(zeroinitializer);
538 KEYWORD(x86_stdcallcc);
539 KEYWORD(x86_fastcallcc);
541 KEYWORD(arm_aapcscc);
542 KEYWORD(arm_aapcs_vfpcc);
543 KEYWORD(msp430_intrcc);
563 KEYWORD(alwaysinline);
568 KEYWORD(noimplicitfloat);
575 KEYWORD(eq); KEYWORD(ne); KEYWORD(slt); KEYWORD(sgt); KEYWORD(sle);
576 KEYWORD(sge); KEYWORD(ult); KEYWORD(ugt); KEYWORD(ule); KEYWORD(uge);
577 KEYWORD(oeq); KEYWORD(one); KEYWORD(olt); KEYWORD(ogt); KEYWORD(ole);
578 KEYWORD(oge); KEYWORD(ord); KEYWORD(uno); KEYWORD(ueq); KEYWORD(une);
581 KEYWORD(blockaddress);
584 // Keywords for types.
585 #define TYPEKEYWORD(STR, LLVMTY) \
586 if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
587 TyVal = LLVMTY; return lltok::Type; }
588 TYPEKEYWORD("void", Type::getVoidTy(Context));
589 TYPEKEYWORD("float", Type::getFloatTy(Context));
590 TYPEKEYWORD("double", Type::getDoubleTy(Context));
591 TYPEKEYWORD("x86_fp80", Type::getX86_FP80Ty(Context));
592 TYPEKEYWORD("fp128", Type::getFP128Ty(Context));
593 TYPEKEYWORD("ppc_fp128", Type::getPPC_FP128Ty(Context));
594 TYPEKEYWORD("label", Type::getLabelTy(Context));
595 TYPEKEYWORD("metadata", Type::getMetadataTy(Context));
598 // Handle special forms for autoupgrading. Drop these in LLVM 3.0. This is
599 // to avoid conflicting with the sext/zext instructions, below.
600 if (Len == 4 && !memcmp(StartChar, "sext", 4)) {
601 // Scan CurPtr ahead, seeing if there is just whitespace before the newline.
602 if (JustWhitespaceNewLine(CurPtr))
603 return lltok::kw_signext;
604 } else if (Len == 4 && !memcmp(StartChar, "zext", 4)) {
605 // Scan CurPtr ahead, seeing if there is just whitespace before the newline.
606 if (JustWhitespaceNewLine(CurPtr))
607 return lltok::kw_zeroext;
608 } else if (Len == 6 && !memcmp(StartChar, "malloc", 6)) {
609 // FIXME: Remove in LLVM 3.0.
610 // Autoupgrade malloc instruction.
611 return lltok::kw_malloc;
612 } else if (Len == 4 && !memcmp(StartChar, "free", 4)) {
613 // FIXME: Remove in LLVM 3.0.
614 // Autoupgrade malloc instruction.
615 return lltok::kw_free;
618 // Keywords for instructions.
619 #define INSTKEYWORD(STR, Enum) \
620 if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) { \
621 UIntVal = Instruction::Enum; return lltok::kw_##STR; }
623 INSTKEYWORD(add, Add); INSTKEYWORD(fadd, FAdd);
624 INSTKEYWORD(sub, Sub); INSTKEYWORD(fsub, FSub);
625 INSTKEYWORD(mul, Mul); INSTKEYWORD(fmul, FMul);
626 INSTKEYWORD(udiv, UDiv); INSTKEYWORD(sdiv, SDiv); INSTKEYWORD(fdiv, FDiv);
627 INSTKEYWORD(urem, URem); INSTKEYWORD(srem, SRem); INSTKEYWORD(frem, FRem);
628 INSTKEYWORD(shl, Shl); INSTKEYWORD(lshr, LShr); INSTKEYWORD(ashr, AShr);
629 INSTKEYWORD(and, And); INSTKEYWORD(or, Or); INSTKEYWORD(xor, Xor);
630 INSTKEYWORD(icmp, ICmp); INSTKEYWORD(fcmp, FCmp);
632 INSTKEYWORD(phi, PHI);
633 INSTKEYWORD(call, Call);
634 INSTKEYWORD(trunc, Trunc);
635 INSTKEYWORD(zext, ZExt);
636 INSTKEYWORD(sext, SExt);
637 INSTKEYWORD(fptrunc, FPTrunc);
638 INSTKEYWORD(fpext, FPExt);
639 INSTKEYWORD(uitofp, UIToFP);
640 INSTKEYWORD(sitofp, SIToFP);
641 INSTKEYWORD(fptoui, FPToUI);
642 INSTKEYWORD(fptosi, FPToSI);
643 INSTKEYWORD(inttoptr, IntToPtr);
644 INSTKEYWORD(ptrtoint, PtrToInt);
645 INSTKEYWORD(bitcast, BitCast);
646 INSTKEYWORD(select, Select);
647 INSTKEYWORD(va_arg, VAArg);
648 INSTKEYWORD(ret, Ret);
650 INSTKEYWORD(switch, Switch);
651 INSTKEYWORD(indirectbr, IndirectBr);
652 INSTKEYWORD(invoke, Invoke);
653 INSTKEYWORD(unwind, Unwind);
654 INSTKEYWORD(unreachable, Unreachable);
656 INSTKEYWORD(alloca, Alloca);
657 INSTKEYWORD(load, Load);
658 INSTKEYWORD(store, Store);
659 INSTKEYWORD(getelementptr, GetElementPtr);
661 INSTKEYWORD(extractelement, ExtractElement);
662 INSTKEYWORD(insertelement, InsertElement);
663 INSTKEYWORD(shufflevector, ShuffleVector);
664 INSTKEYWORD(getresult, ExtractValue);
665 INSTKEYWORD(extractvalue, ExtractValue);
666 INSTKEYWORD(insertvalue, InsertValue);
669 // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
670 // the CFE to avoid forcing it to deal with 64-bit numbers.
671 if ((TokStart[0] == 'u' || TokStart[0] == 's') &&
672 TokStart[1] == '0' && TokStart[2] == 'x' && isxdigit(TokStart[3])) {
673 int len = CurPtr-TokStart-3;
674 uint32_t bits = len * 4;
675 APInt Tmp(bits, StringRef(TokStart+3, len), 16);
676 uint32_t activeBits = Tmp.getActiveBits();
677 if (activeBits > 0 && activeBits < bits)
678 Tmp.trunc(activeBits);
679 APSIntVal = APSInt(Tmp, TokStart[0] == 'u');
680 return lltok::APSInt;
683 // If this is "cc1234", return this as just "cc".
684 if (TokStart[0] == 'c' && TokStart[1] == 'c') {
689 // If this starts with "call", return it as CALL. This is to support old
690 // broken .ll files. FIXME: remove this with LLVM 3.0.
691 if (CurPtr-TokStart > 4 && !memcmp(TokStart, "call", 4)) {
693 UIntVal = Instruction::Call;
694 return lltok::kw_call;
697 // Finally, if this isn't known, return an error.
703 /// Lex0x: Handle productions that start with 0x, knowing that it matches and
704 /// that this is not a label:
705 /// HexFPConstant 0x[0-9A-Fa-f]+
706 /// HexFP80Constant 0xK[0-9A-Fa-f]+
707 /// HexFP128Constant 0xL[0-9A-Fa-f]+
708 /// HexPPC128Constant 0xM[0-9A-Fa-f]+
709 lltok::Kind LLLexer::Lex0x() {
710 CurPtr = TokStart + 2;
713 if (CurPtr[0] >= 'K' && CurPtr[0] <= 'M') {
719 if (!isxdigit(CurPtr[0])) {
720 // Bad token, return it as an error.
725 while (isxdigit(CurPtr[0]))
729 // HexFPConstant - Floating point constant represented in IEEE format as a
730 // hexadecimal number for when exponential notation is not precise enough.
731 // Float and double only.
732 APFloatVal = APFloat(BitsToDouble(HexIntToVal(TokStart+2, CurPtr)));
733 return lltok::APFloat;
738 default: llvm_unreachable("Unknown kind!");
740 // F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
741 FP80HexToIntPair(TokStart+3, CurPtr, Pair);
742 APFloatVal = APFloat(APInt(80, 2, Pair));
743 return lltok::APFloat;
745 // F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
746 HexToIntPair(TokStart+3, CurPtr, Pair);
747 APFloatVal = APFloat(APInt(128, 2, Pair), true);
748 return lltok::APFloat;
750 // PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
751 HexToIntPair(TokStart+3, CurPtr, Pair);
752 APFloatVal = APFloat(APInt(128, 2, Pair));
753 return lltok::APFloat;
757 /// LexIdentifier: Handle several related productions:
758 /// Label [-a-zA-Z$._0-9]+:
760 /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
762 /// HexFPConstant 0x[0-9A-Fa-f]+
763 /// HexFP80Constant 0xK[0-9A-Fa-f]+
764 /// HexFP128Constant 0xL[0-9A-Fa-f]+
765 /// HexPPC128Constant 0xM[0-9A-Fa-f]+
766 lltok::Kind LLLexer::LexDigitOrNegative() {
767 // If the letter after the negative is a number, this is probably a label.
768 if (!isdigit(TokStart[0]) && !isdigit(CurPtr[0])) {
769 // Okay, this is not a number after the -, it's probably a label.
770 if (const char *End = isLabelTail(CurPtr)) {
771 StrVal.assign(TokStart, End-1);
773 return lltok::LabelStr;
779 // At this point, it is either a label, int or fp constant.
781 // Skip digits, we have at least one.
782 for (; isdigit(CurPtr[0]); ++CurPtr)
785 // Check to see if this really is a label afterall, e.g. "-1:".
786 if (isLabelChar(CurPtr[0]) || CurPtr[0] == ':') {
787 if (const char *End = isLabelTail(CurPtr)) {
788 StrVal.assign(TokStart, End-1);
790 return lltok::LabelStr;
794 // If the next character is a '.', then it is a fp value, otherwise its
796 if (CurPtr[0] != '.') {
797 if (TokStart[0] == '0' && TokStart[1] == 'x')
799 unsigned Len = CurPtr-TokStart;
800 uint32_t numBits = ((Len * 64) / 19) + 2;
801 APInt Tmp(numBits, StringRef(TokStart, Len), 10);
802 if (TokStart[0] == '-') {
803 uint32_t minBits = Tmp.getMinSignedBits();
804 if (minBits > 0 && minBits < numBits)
806 APSIntVal = APSInt(Tmp, false);
808 uint32_t activeBits = Tmp.getActiveBits();
809 if (activeBits > 0 && activeBits < numBits)
810 Tmp.trunc(activeBits);
811 APSIntVal = APSInt(Tmp, true);
813 return lltok::APSInt;
818 // Skip over [0-9]*([eE][-+]?[0-9]+)?
819 while (isdigit(CurPtr[0])) ++CurPtr;
821 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
822 if (isdigit(CurPtr[1]) ||
823 ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
825 while (isdigit(CurPtr[0])) ++CurPtr;
829 APFloatVal = APFloat(atof(TokStart));
830 return lltok::APFloat;
833 /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
834 lltok::Kind LLLexer::LexPositive() {
835 // If the letter after the negative is a number, this is probably not a
837 if (!isdigit(CurPtr[0]))
841 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
844 // At this point, we need a '.'.
845 if (CurPtr[0] != '.') {
852 // Skip over [0-9]*([eE][-+]?[0-9]+)?
853 while (isdigit(CurPtr[0])) ++CurPtr;
855 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
856 if (isdigit(CurPtr[1]) ||
857 ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
859 while (isdigit(CurPtr[0])) ++CurPtr;
863 APFloatVal = APFloat(atof(TokStart));
864 return lltok::APFloat;