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/ADT/Twine.h"
19 #include "llvm/Assembly/Parser.h"
20 #include "llvm/Support/ErrorHandling.h"
21 #include "llvm/Support/MemoryBuffer.h"
22 #include "llvm/Support/MathExtras.h"
23 #include "llvm/Support/SourceMgr.h"
24 #include "llvm/Support/raw_ostream.h"
31 bool LLLexer::Error(LocTy ErrorLoc, const Twine &Msg) const {
32 ErrorInfo = SM.GetMessage(ErrorLoc, Msg, "error");
36 //===----------------------------------------------------------------------===//
38 //===----------------------------------------------------------------------===//
40 // atoull - Convert an ascii string of decimal digits into the unsigned long
41 // long representation... this does not have to do input error checking,
42 // because we know that the input will be matched by a suitable regex...
44 uint64_t LLLexer::atoull(const char *Buffer, const char *End) {
46 for (; Buffer != End; Buffer++) {
47 uint64_t OldRes = Result;
49 Result += *Buffer-'0';
50 if (Result < OldRes) { // Uh, oh, overflow detected!!!
51 Error("constant bigger than 64 bits detected!");
58 uint64_t LLLexer::HexIntToVal(const char *Buffer, const char *End) {
60 for (; Buffer != End; ++Buffer) {
61 uint64_t OldRes = Result;
64 if (C >= '0' && C <= '9')
66 else if (C >= 'A' && C <= 'F')
68 else if (C >= 'a' && C <= 'f')
71 if (Result < OldRes) { // Uh, oh, overflow detected!!!
72 Error("constant bigger than 64 bits detected!");
79 void LLLexer::HexToIntPair(const char *Buffer, const char *End,
82 for (int i=0; i<16; i++, Buffer++) {
83 assert(Buffer != End);
86 if (C >= '0' && C <= '9')
88 else if (C >= 'A' && C <= 'F')
90 else if (C >= 'a' && C <= 'f')
94 for (int i=0; i<16 && Buffer != End; i++, Buffer++) {
97 if (C >= '0' && C <= '9')
99 else if (C >= 'A' && C <= 'F')
101 else if (C >= 'a' && C <= 'f')
105 Error("constant bigger than 128 bits detected!");
108 /// FP80HexToIntPair - translate an 80 bit FP80 number (20 hexits) into
109 /// { low64, high16 } as usual for an APInt.
110 void LLLexer::FP80HexToIntPair(const char *Buffer, const char *End,
113 for (int i=0; i<4 && Buffer != End; i++, Buffer++) {
114 assert(Buffer != End);
117 if (C >= '0' && C <= '9')
119 else if (C >= 'A' && C <= 'F')
121 else if (C >= 'a' && C <= 'f')
125 for (int i=0; i<16; i++, Buffer++) {
128 if (C >= '0' && C <= '9')
130 else if (C >= 'A' && C <= 'F')
132 else if (C >= 'a' && C <= 'f')
136 Error("constant bigger than 128 bits detected!");
139 // UnEscapeLexed - Run through the specified buffer and change \xx codes to the
140 // appropriate character.
141 static void UnEscapeLexed(std::string &Str) {
142 if (Str.empty()) return;
144 char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
146 for (char *BIn = Buffer; BIn != EndBuffer; ) {
147 if (BIn[0] == '\\') {
148 if (BIn < EndBuffer-1 && BIn[1] == '\\') {
149 *BOut++ = '\\'; // Two \ becomes one
151 } else if (BIn < EndBuffer-2 && isxdigit(BIn[1]) && isxdigit(BIn[2])) {
152 char Tmp = BIn[3]; BIn[3] = 0; // Terminate string
153 *BOut = (char)strtol(BIn+1, 0, 16); // Convert to number
154 BIn[3] = Tmp; // Restore character
155 BIn += 3; // Skip over handled chars
164 Str.resize(BOut-Buffer);
167 /// isLabelChar - Return true for [-a-zA-Z$._0-9].
168 static bool isLabelChar(char C) {
169 return isalnum(C) || C == '-' || C == '$' || C == '.' || C == '_';
173 /// isLabelTail - Return true if this pointer points to a valid end of a label.
174 static const char *isLabelTail(const char *CurPtr) {
176 if (CurPtr[0] == ':') return CurPtr+1;
177 if (!isLabelChar(CurPtr[0])) return 0;
184 //===----------------------------------------------------------------------===//
186 //===----------------------------------------------------------------------===//
188 LLLexer::LLLexer(MemoryBuffer *StartBuf, SourceMgr &sm, SMDiagnostic &Err,
190 : CurBuf(StartBuf), ErrorInfo(Err), SM(sm), Context(C), APFloatVal(0.0) {
191 CurPtr = CurBuf->getBufferStart();
194 std::string LLLexer::getFilename() const {
195 return CurBuf->getBufferIdentifier();
198 int LLLexer::getNextChar() {
199 char CurChar = *CurPtr++;
201 default: return (unsigned char)CurChar;
203 // A nul character in the stream is either the end of the current buffer or
204 // a random nul in the file. Disambiguate that here.
205 if (CurPtr-1 != CurBuf->getBufferEnd())
206 return 0; // Just whitespace.
208 // Otherwise, return end of file.
209 --CurPtr; // Another call to lex will return EOF again.
215 lltok::Kind LLLexer::LexToken() {
218 int CurChar = getNextChar();
221 // Handle letters: [a-zA-Z_]
222 if (isalpha(CurChar) || CurChar == '_')
223 return LexIdentifier();
226 case EOF: return lltok::Eof;
232 // Ignore whitespace.
234 case '+': return LexPositive();
235 case '@': return LexAt();
236 case '%': return LexPercent();
237 case '"': return LexQuote();
239 if (const char *Ptr = isLabelTail(CurPtr)) {
241 StrVal.assign(TokStart, CurPtr-1);
242 return lltok::LabelStr;
244 if (CurPtr[0] == '.' && CurPtr[1] == '.') {
246 return lltok::dotdotdot;
250 if (const char *Ptr = isLabelTail(CurPtr)) {
252 StrVal.assign(TokStart, CurPtr-1);
253 return lltok::LabelStr;
259 case '!': return LexExclaim();
260 case '0': case '1': case '2': case '3': case '4':
261 case '5': case '6': case '7': case '8': case '9':
263 return LexDigitOrNegative();
264 case '=': return lltok::equal;
265 case '[': return lltok::lsquare;
266 case ']': return lltok::rsquare;
267 case '{': return lltok::lbrace;
268 case '}': return lltok::rbrace;
269 case '<': return lltok::less;
270 case '>': return lltok::greater;
271 case '(': return lltok::lparen;
272 case ')': return lltok::rparen;
273 case ',': return lltok::comma;
274 case '*': return lltok::star;
275 case '\\': return lltok::backslash;
279 void LLLexer::SkipLineComment() {
281 if (CurPtr[0] == '\n' || CurPtr[0] == '\r' || getNextChar() == EOF)
286 /// LexAt - Lex all tokens that start with an @ character:
287 /// GlobalVar @\"[^\"]*\"
288 /// GlobalVar @[-a-zA-Z$._][-a-zA-Z$._0-9]*
289 /// GlobalVarID @[0-9]+
290 lltok::Kind LLLexer::LexAt() {
291 // Handle AtStringConstant: @\"[^\"]*\"
292 if (CurPtr[0] == '"') {
296 int CurChar = getNextChar();
298 if (CurChar == EOF) {
299 Error("end of file in global variable name");
302 if (CurChar == '"') {
303 StrVal.assign(TokStart+2, CurPtr-1);
304 UnEscapeLexed(StrVal);
305 return lltok::GlobalVar;
310 // Handle GlobalVarName: @[-a-zA-Z$._][-a-zA-Z$._0-9]*
311 if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
312 CurPtr[0] == '.' || CurPtr[0] == '_') {
314 while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
315 CurPtr[0] == '.' || CurPtr[0] == '_')
318 StrVal.assign(TokStart+1, CurPtr); // Skip @
319 return lltok::GlobalVar;
322 // Handle GlobalVarID: @[0-9]+
323 if (isdigit(CurPtr[0])) {
324 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
327 uint64_t Val = atoull(TokStart+1, CurPtr);
328 if ((unsigned)Val != Val)
329 Error("invalid value number (too large)!");
330 UIntVal = unsigned(Val);
331 return lltok::GlobalID;
338 /// LexPercent - Lex all tokens that start with a % character:
339 /// LocalVar ::= %\"[^\"]*\"
340 /// LocalVar ::= %[-a-zA-Z$._][-a-zA-Z$._0-9]*
341 /// LocalVarID ::= %[0-9]+
342 lltok::Kind LLLexer::LexPercent() {
343 // Handle LocalVarName: %\"[^\"]*\"
344 if (CurPtr[0] == '"') {
348 int CurChar = getNextChar();
350 if (CurChar == EOF) {
351 Error("end of file in string constant");
354 if (CurChar == '"') {
355 StrVal.assign(TokStart+2, CurPtr-1);
356 UnEscapeLexed(StrVal);
357 return lltok::LocalVar;
362 // Handle LocalVarName: %[-a-zA-Z$._][-a-zA-Z$._0-9]*
363 if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
364 CurPtr[0] == '.' || CurPtr[0] == '_') {
366 while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
367 CurPtr[0] == '.' || CurPtr[0] == '_')
370 StrVal.assign(TokStart+1, CurPtr); // Skip %
371 return lltok::LocalVar;
374 // Handle LocalVarID: %[0-9]+
375 if (isdigit(CurPtr[0])) {
376 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
379 uint64_t Val = atoull(TokStart+1, CurPtr);
380 if ((unsigned)Val != Val)
381 Error("invalid value number (too large)!");
382 UIntVal = unsigned(Val);
383 return lltok::LocalVarID;
389 /// LexQuote - Lex all tokens that start with a " character:
390 /// QuoteLabel "[^"]+":
391 /// StringConstant "[^"]*"
392 lltok::Kind LLLexer::LexQuote() {
394 int CurChar = getNextChar();
396 if (CurChar == EOF) {
397 Error("end of file in quoted string");
401 if (CurChar != '"') continue;
403 if (CurPtr[0] != ':') {
404 StrVal.assign(TokStart+1, CurPtr-1);
405 UnEscapeLexed(StrVal);
406 return lltok::StringConstant;
410 StrVal.assign(TokStart+1, CurPtr-2);
411 UnEscapeLexed(StrVal);
412 return lltok::LabelStr;
416 static bool JustWhitespaceNewLine(const char *&Ptr) {
417 const char *ThisPtr = Ptr;
418 while (*ThisPtr == ' ' || *ThisPtr == '\t')
420 if (*ThisPtr == '\n' || *ThisPtr == '\r') {
430 lltok::Kind LLLexer::LexExclaim() {
431 // Lex a metadata name as a MetadataVar.
432 if (isalpha(CurPtr[0])) {
434 while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
435 CurPtr[0] == '.' || CurPtr[0] == '_')
438 StrVal.assign(TokStart+1, CurPtr); // Skip !
439 return lltok::MetadataVar;
441 return lltok::exclaim;
444 /// LexIdentifier: Handle several related productions:
445 /// Label [-a-zA-Z$._0-9]+:
446 /// IntegerType i[0-9]+
447 /// Keyword sdiv, float, ...
448 /// HexIntConstant [us]0x[0-9A-Fa-f]+
449 lltok::Kind LLLexer::LexIdentifier() {
450 const char *StartChar = CurPtr;
451 const char *IntEnd = CurPtr[-1] == 'i' ? 0 : StartChar;
452 const char *KeywordEnd = 0;
454 for (; isLabelChar(*CurPtr); ++CurPtr) {
455 // If we decide this is an integer, remember the end of the sequence.
456 if (!IntEnd && !isdigit(*CurPtr)) IntEnd = CurPtr;
457 if (!KeywordEnd && !isalnum(*CurPtr) && *CurPtr != '_') KeywordEnd = CurPtr;
460 // If we stopped due to a colon, this really is a label.
461 if (*CurPtr == ':') {
462 StrVal.assign(StartChar-1, CurPtr++);
463 return lltok::LabelStr;
466 // Otherwise, this wasn't a label. If this was valid as an integer type,
468 if (IntEnd == 0) IntEnd = CurPtr;
469 if (IntEnd != StartChar) {
471 uint64_t NumBits = atoull(StartChar, CurPtr);
472 if (NumBits < IntegerType::MIN_INT_BITS ||
473 NumBits > IntegerType::MAX_INT_BITS) {
474 Error("bitwidth for integer type out of range!");
477 TyVal = IntegerType::get(Context, NumBits);
481 // Otherwise, this was a letter sequence. See which keyword this is.
482 if (KeywordEnd == 0) KeywordEnd = CurPtr;
485 unsigned Len = CurPtr-StartChar;
486 #define KEYWORD(STR) \
487 if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) \
488 return lltok::kw_##STR;
490 KEYWORD(begin); KEYWORD(end);
491 KEYWORD(true); KEYWORD(false);
492 KEYWORD(declare); KEYWORD(define);
493 KEYWORD(global); KEYWORD(constant);
496 KEYWORD(linker_private);
497 KEYWORD(linker_private_weak);
498 KEYWORD(linker_private_weak_def_auto);
500 KEYWORD(available_externally);
502 KEYWORD(linkonce_odr);
512 KEYWORD(unnamed_addr);
513 KEYWORD(extern_weak);
515 KEYWORD(thread_local);
516 KEYWORD(zeroinitializer);
543 KEYWORD(x86_stdcallcc);
544 KEYWORD(x86_fastcallcc);
545 KEYWORD(x86_thiscallcc);
547 KEYWORD(arm_aapcscc);
548 KEYWORD(arm_aapcs_vfpcc);
549 KEYWORD(msp430_intrcc);
571 KEYWORD(alwaysinline);
576 KEYWORD(noimplicitfloat);
583 KEYWORD(eq); KEYWORD(ne); KEYWORD(slt); KEYWORD(sgt); KEYWORD(sle);
584 KEYWORD(sge); KEYWORD(ult); KEYWORD(ugt); KEYWORD(ule); KEYWORD(uge);
585 KEYWORD(oeq); KEYWORD(one); KEYWORD(olt); KEYWORD(ogt); KEYWORD(ole);
586 KEYWORD(oge); KEYWORD(ord); KEYWORD(uno); KEYWORD(ueq); KEYWORD(une);
589 KEYWORD(blockaddress);
594 // Keywords for types.
595 #define TYPEKEYWORD(STR, LLVMTY) \
596 if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
597 TyVal = LLVMTY; return lltok::Type; }
598 TYPEKEYWORD("void", Type::getVoidTy(Context));
599 TYPEKEYWORD("float", Type::getFloatTy(Context));
600 TYPEKEYWORD("double", Type::getDoubleTy(Context));
601 TYPEKEYWORD("x86_fp80", Type::getX86_FP80Ty(Context));
602 TYPEKEYWORD("fp128", Type::getFP128Ty(Context));
603 TYPEKEYWORD("ppc_fp128", Type::getPPC_FP128Ty(Context));
604 TYPEKEYWORD("label", Type::getLabelTy(Context));
605 TYPEKEYWORD("metadata", Type::getMetadataTy(Context));
606 TYPEKEYWORD("x86_mmx", Type::getX86_MMXTy(Context));
609 // Handle special forms for autoupgrading. Drop these in LLVM 3.0. This is
610 // to avoid conflicting with the sext/zext instructions, below.
611 if (Len == 4 && !memcmp(StartChar, "sext", 4)) {
612 // Scan CurPtr ahead, seeing if there is just whitespace before the newline.
613 if (JustWhitespaceNewLine(CurPtr))
614 return lltok::kw_signext;
615 } else if (Len == 4 && !memcmp(StartChar, "zext", 4)) {
616 // Scan CurPtr ahead, seeing if there is just whitespace before the newline.
617 if (JustWhitespaceNewLine(CurPtr))
618 return lltok::kw_zeroext;
619 } else if (Len == 6 && !memcmp(StartChar, "malloc", 6)) {
620 // FIXME: Remove in LLVM 3.0.
621 // Autoupgrade malloc instruction.
622 return lltok::kw_malloc;
623 } else if (Len == 4 && !memcmp(StartChar, "free", 4)) {
624 // FIXME: Remove in LLVM 3.0.
625 // Autoupgrade malloc instruction.
626 return lltok::kw_free;
629 // Keywords for instructions.
630 #define INSTKEYWORD(STR, Enum) \
631 if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) { \
632 UIntVal = Instruction::Enum; return lltok::kw_##STR; }
634 INSTKEYWORD(add, Add); INSTKEYWORD(fadd, FAdd);
635 INSTKEYWORD(sub, Sub); INSTKEYWORD(fsub, FSub);
636 INSTKEYWORD(mul, Mul); INSTKEYWORD(fmul, FMul);
637 INSTKEYWORD(udiv, UDiv); INSTKEYWORD(sdiv, SDiv); INSTKEYWORD(fdiv, FDiv);
638 INSTKEYWORD(urem, URem); INSTKEYWORD(srem, SRem); INSTKEYWORD(frem, FRem);
639 INSTKEYWORD(shl, Shl); INSTKEYWORD(lshr, LShr); INSTKEYWORD(ashr, AShr);
640 INSTKEYWORD(and, And); INSTKEYWORD(or, Or); INSTKEYWORD(xor, Xor);
641 INSTKEYWORD(icmp, ICmp); INSTKEYWORD(fcmp, FCmp);
643 INSTKEYWORD(phi, PHI);
644 INSTKEYWORD(call, Call);
645 INSTKEYWORD(trunc, Trunc);
646 INSTKEYWORD(zext, ZExt);
647 INSTKEYWORD(sext, SExt);
648 INSTKEYWORD(fptrunc, FPTrunc);
649 INSTKEYWORD(fpext, FPExt);
650 INSTKEYWORD(uitofp, UIToFP);
651 INSTKEYWORD(sitofp, SIToFP);
652 INSTKEYWORD(fptoui, FPToUI);
653 INSTKEYWORD(fptosi, FPToSI);
654 INSTKEYWORD(inttoptr, IntToPtr);
655 INSTKEYWORD(ptrtoint, PtrToInt);
656 INSTKEYWORD(bitcast, BitCast);
657 INSTKEYWORD(select, Select);
658 INSTKEYWORD(va_arg, VAArg);
659 INSTKEYWORD(ret, Ret);
661 INSTKEYWORD(switch, Switch);
662 INSTKEYWORD(indirectbr, IndirectBr);
663 INSTKEYWORD(invoke, Invoke);
664 INSTKEYWORD(unwind, Unwind);
665 INSTKEYWORD(unreachable, Unreachable);
667 INSTKEYWORD(alloca, Alloca);
668 INSTKEYWORD(load, Load);
669 INSTKEYWORD(store, Store);
670 INSTKEYWORD(getelementptr, GetElementPtr);
672 INSTKEYWORD(extractelement, ExtractElement);
673 INSTKEYWORD(insertelement, InsertElement);
674 INSTKEYWORD(shufflevector, ShuffleVector);
675 INSTKEYWORD(getresult, ExtractValue);
676 INSTKEYWORD(extractvalue, ExtractValue);
677 INSTKEYWORD(insertvalue, InsertValue);
680 // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
681 // the CFE to avoid forcing it to deal with 64-bit numbers.
682 if ((TokStart[0] == 'u' || TokStart[0] == 's') &&
683 TokStart[1] == '0' && TokStart[2] == 'x' && isxdigit(TokStart[3])) {
684 int len = CurPtr-TokStart-3;
685 uint32_t bits = len * 4;
686 APInt Tmp(bits, StringRef(TokStart+3, len), 16);
687 uint32_t activeBits = Tmp.getActiveBits();
688 if (activeBits > 0 && activeBits < bits)
689 Tmp = Tmp.trunc(activeBits);
690 APSIntVal = APSInt(Tmp, TokStart[0] == 'u');
691 return lltok::APSInt;
694 // If this is "cc1234", return this as just "cc".
695 if (TokStart[0] == 'c' && TokStart[1] == 'c') {
700 // If this starts with "call", return it as CALL. This is to support old
701 // broken .ll files. FIXME: remove this with LLVM 3.0.
702 if (CurPtr-TokStart > 4 && !memcmp(TokStart, "call", 4)) {
704 UIntVal = Instruction::Call;
705 return lltok::kw_call;
708 // Finally, if this isn't known, return an error.
714 /// Lex0x: Handle productions that start with 0x, knowing that it matches and
715 /// that this is not a label:
716 /// HexFPConstant 0x[0-9A-Fa-f]+
717 /// HexFP80Constant 0xK[0-9A-Fa-f]+
718 /// HexFP128Constant 0xL[0-9A-Fa-f]+
719 /// HexPPC128Constant 0xM[0-9A-Fa-f]+
720 lltok::Kind LLLexer::Lex0x() {
721 CurPtr = TokStart + 2;
724 if (CurPtr[0] >= 'K' && CurPtr[0] <= 'M') {
730 if (!isxdigit(CurPtr[0])) {
731 // Bad token, return it as an error.
736 while (isxdigit(CurPtr[0]))
740 // HexFPConstant - Floating point constant represented in IEEE format as a
741 // hexadecimal number for when exponential notation is not precise enough.
742 // Float and double only.
743 APFloatVal = APFloat(BitsToDouble(HexIntToVal(TokStart+2, CurPtr)));
744 return lltok::APFloat;
749 default: llvm_unreachable("Unknown kind!");
751 // F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
752 FP80HexToIntPair(TokStart+3, CurPtr, Pair);
753 APFloatVal = APFloat(APInt(80, 2, Pair));
754 return lltok::APFloat;
756 // F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
757 HexToIntPair(TokStart+3, CurPtr, Pair);
758 APFloatVal = APFloat(APInt(128, 2, Pair), true);
759 return lltok::APFloat;
761 // PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
762 HexToIntPair(TokStart+3, CurPtr, Pair);
763 APFloatVal = APFloat(APInt(128, 2, Pair));
764 return lltok::APFloat;
768 /// LexIdentifier: Handle several related productions:
769 /// Label [-a-zA-Z$._0-9]+:
771 /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
773 /// HexFPConstant 0x[0-9A-Fa-f]+
774 /// HexFP80Constant 0xK[0-9A-Fa-f]+
775 /// HexFP128Constant 0xL[0-9A-Fa-f]+
776 /// HexPPC128Constant 0xM[0-9A-Fa-f]+
777 lltok::Kind LLLexer::LexDigitOrNegative() {
778 // If the letter after the negative is a number, this is probably a label.
779 if (!isdigit(TokStart[0]) && !isdigit(CurPtr[0])) {
780 // Okay, this is not a number after the -, it's probably a label.
781 if (const char *End = isLabelTail(CurPtr)) {
782 StrVal.assign(TokStart, End-1);
784 return lltok::LabelStr;
790 // At this point, it is either a label, int or fp constant.
792 // Skip digits, we have at least one.
793 for (; isdigit(CurPtr[0]); ++CurPtr)
796 // Check to see if this really is a label afterall, e.g. "-1:".
797 if (isLabelChar(CurPtr[0]) || CurPtr[0] == ':') {
798 if (const char *End = isLabelTail(CurPtr)) {
799 StrVal.assign(TokStart, End-1);
801 return lltok::LabelStr;
805 // If the next character is a '.', then it is a fp value, otherwise its
807 if (CurPtr[0] != '.') {
808 if (TokStart[0] == '0' && TokStart[1] == 'x')
810 unsigned Len = CurPtr-TokStart;
811 uint32_t numBits = ((Len * 64) / 19) + 2;
812 APInt Tmp(numBits, StringRef(TokStart, Len), 10);
813 if (TokStart[0] == '-') {
814 uint32_t minBits = Tmp.getMinSignedBits();
815 if (minBits > 0 && minBits < numBits)
816 Tmp = Tmp.trunc(minBits);
817 APSIntVal = APSInt(Tmp, false);
819 uint32_t activeBits = Tmp.getActiveBits();
820 if (activeBits > 0 && activeBits < numBits)
821 Tmp = Tmp.trunc(activeBits);
822 APSIntVal = APSInt(Tmp, true);
824 return lltok::APSInt;
829 // Skip over [0-9]*([eE][-+]?[0-9]+)?
830 while (isdigit(CurPtr[0])) ++CurPtr;
832 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
833 if (isdigit(CurPtr[1]) ||
834 ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
836 while (isdigit(CurPtr[0])) ++CurPtr;
840 APFloatVal = APFloat(std::atof(TokStart));
841 return lltok::APFloat;
844 /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
845 lltok::Kind LLLexer::LexPositive() {
846 // If the letter after the negative is a number, this is probably not a
848 if (!isdigit(CurPtr[0]))
852 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
855 // At this point, we need a '.'.
856 if (CurPtr[0] != '.') {
863 // Skip over [0-9]*([eE][-+]?[0-9]+)?
864 while (isdigit(CurPtr[0])) ++CurPtr;
866 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
867 if (isdigit(CurPtr[1]) ||
868 ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
870 while (isdigit(CurPtr[0])) ++CurPtr;
874 APFloatVal = APFloat(std::atof(TokStart));
875 return lltok::APFloat;