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/ADT/StringExtras.h"
16 #include "llvm/ADT/Twine.h"
17 #include "llvm/Assembly/Parser.h"
18 #include "llvm/IR/DerivedTypes.h"
19 #include "llvm/IR/Instruction.h"
20 #include "llvm/IR/LLVMContext.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/MathExtras.h"
23 #include "llvm/Support/MemoryBuffer.h"
24 #include "llvm/Support/SourceMgr.h"
25 #include "llvm/Support/raw_ostream.h"
32 bool LLLexer::Error(LocTy ErrorLoc, const Twine &Msg) const {
33 ErrorInfo = SM.GetMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
37 //===----------------------------------------------------------------------===//
39 //===----------------------------------------------------------------------===//
41 // atoull - Convert an ascii string of decimal digits into the unsigned long
42 // long representation... this does not have to do input error checking,
43 // because we know that the input will be matched by a suitable regex...
45 uint64_t LLLexer::atoull(const char *Buffer, const char *End) {
47 for (; Buffer != End; Buffer++) {
48 uint64_t OldRes = Result;
50 Result += *Buffer-'0';
51 if (Result < OldRes) { // Uh, oh, overflow detected!!!
52 Error("constant bigger than 64 bits detected!");
59 uint64_t LLLexer::HexIntToVal(const char *Buffer, const char *End) {
61 for (; Buffer != End; ++Buffer) {
62 uint64_t OldRes = Result;
64 Result += hexDigitValue(*Buffer);
66 if (Result < OldRes) { // Uh, oh, overflow detected!!!
67 Error("constant bigger than 64 bits detected!");
74 void LLLexer::HexToIntPair(const char *Buffer, const char *End,
77 for (int i=0; i<16; i++, Buffer++) {
78 assert(Buffer != End);
80 Pair[0] += hexDigitValue(*Buffer);
83 for (int i=0; i<16 && Buffer != End; i++, Buffer++) {
85 Pair[1] += hexDigitValue(*Buffer);
88 Error("constant bigger than 128 bits detected!");
91 /// FP80HexToIntPair - translate an 80 bit FP80 number (20 hexits) into
92 /// { low64, high16 } as usual for an APInt.
93 void LLLexer::FP80HexToIntPair(const char *Buffer, const char *End,
96 for (int i=0; i<4 && Buffer != End; i++, Buffer++) {
97 assert(Buffer != End);
99 Pair[1] += hexDigitValue(*Buffer);
102 for (int i=0; i<16; i++, Buffer++) {
104 Pair[0] += hexDigitValue(*Buffer);
107 Error("constant bigger than 128 bits detected!");
110 // UnEscapeLexed - Run through the specified buffer and change \xx codes to the
111 // appropriate character.
112 static void UnEscapeLexed(std::string &Str) {
113 if (Str.empty()) return;
115 char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
117 for (char *BIn = Buffer; BIn != EndBuffer; ) {
118 if (BIn[0] == '\\') {
119 if (BIn < EndBuffer-1 && BIn[1] == '\\') {
120 *BOut++ = '\\'; // Two \ becomes one
122 } else if (BIn < EndBuffer-2 && isxdigit(BIn[1]) && isxdigit(BIn[2])) {
123 *BOut = hexDigitValue(BIn[1]) * 16 + hexDigitValue(BIn[2]);
124 BIn += 3; // Skip over handled chars
133 Str.resize(BOut-Buffer);
136 /// isLabelChar - Return true for [-a-zA-Z$._0-9].
137 static bool isLabelChar(char C) {
138 return isalnum(C) || C == '-' || C == '$' || C == '.' || C == '_';
142 /// isLabelTail - Return true if this pointer points to a valid end of a label.
143 static const char *isLabelTail(const char *CurPtr) {
145 if (CurPtr[0] == ':') return CurPtr+1;
146 if (!isLabelChar(CurPtr[0])) return 0;
153 //===----------------------------------------------------------------------===//
155 //===----------------------------------------------------------------------===//
157 LLLexer::LLLexer(MemoryBuffer *StartBuf, SourceMgr &sm, SMDiagnostic &Err,
159 : CurBuf(StartBuf), ErrorInfo(Err), SM(sm), Context(C), APFloatVal(0.0) {
160 CurPtr = CurBuf->getBufferStart();
163 std::string LLLexer::getFilename() const {
164 return CurBuf->getBufferIdentifier();
167 int LLLexer::getNextChar() {
168 char CurChar = *CurPtr++;
170 default: return (unsigned char)CurChar;
172 // A nul character in the stream is either the end of the current buffer or
173 // a random nul in the file. Disambiguate that here.
174 if (CurPtr-1 != CurBuf->getBufferEnd())
175 return 0; // Just whitespace.
177 // Otherwise, return end of file.
178 --CurPtr; // Another call to lex will return EOF again.
184 lltok::Kind LLLexer::LexToken() {
187 int CurChar = getNextChar();
190 // Handle letters: [a-zA-Z_]
191 if (isalpha(CurChar) || CurChar == '_')
192 return LexIdentifier();
195 case EOF: return lltok::Eof;
201 // Ignore whitespace.
203 case '+': return LexPositive();
204 case '@': return LexAt();
205 case '%': return LexPercent();
206 case '"': return LexQuote();
208 if (const char *Ptr = isLabelTail(CurPtr)) {
210 StrVal.assign(TokStart, CurPtr-1);
211 return lltok::LabelStr;
213 if (CurPtr[0] == '.' && CurPtr[1] == '.') {
215 return lltok::dotdotdot;
219 if (const char *Ptr = isLabelTail(CurPtr)) {
221 StrVal.assign(TokStart, CurPtr-1);
222 return lltok::LabelStr;
228 case '!': return LexExclaim();
229 case '0': case '1': case '2': case '3': case '4':
230 case '5': case '6': case '7': case '8': case '9':
232 return LexDigitOrNegative();
233 case '=': return lltok::equal;
234 case '[': return lltok::lsquare;
235 case ']': return lltok::rsquare;
236 case '{': return lltok::lbrace;
237 case '}': return lltok::rbrace;
238 case '<': return lltok::less;
239 case '>': return lltok::greater;
240 case '(': return lltok::lparen;
241 case ')': return lltok::rparen;
242 case ',': return lltok::comma;
243 case '*': return lltok::star;
244 case '\\': return lltok::backslash;
248 void LLLexer::SkipLineComment() {
250 if (CurPtr[0] == '\n' || CurPtr[0] == '\r' || getNextChar() == EOF)
255 /// LexAt - Lex all tokens that start with an @ character:
256 /// GlobalVar @\"[^\"]*\"
257 /// GlobalVar @[-a-zA-Z$._][-a-zA-Z$._0-9]*
258 /// GlobalVarID @[0-9]+
259 lltok::Kind LLLexer::LexAt() {
260 // Handle AtStringConstant: @\"[^\"]*\"
261 if (CurPtr[0] == '"') {
265 int CurChar = getNextChar();
267 if (CurChar == EOF) {
268 Error("end of file in global variable name");
271 if (CurChar == '"') {
272 StrVal.assign(TokStart+2, CurPtr-1);
273 UnEscapeLexed(StrVal);
274 return lltok::GlobalVar;
279 // Handle GlobalVarName: @[-a-zA-Z$._][-a-zA-Z$._0-9]*
281 return lltok::GlobalVar;
283 // Handle GlobalVarID: @[0-9]+
284 if (isdigit(CurPtr[0])) {
285 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
288 uint64_t Val = atoull(TokStart+1, CurPtr);
289 if ((unsigned)Val != Val)
290 Error("invalid value number (too large)!");
291 UIntVal = unsigned(Val);
292 return lltok::GlobalID;
298 /// ReadString - Read a string until the closing quote.
299 lltok::Kind LLLexer::ReadString(lltok::Kind kind) {
300 const char *Start = CurPtr;
302 int CurChar = getNextChar();
304 if (CurChar == EOF) {
305 Error("end of file in string constant");
308 if (CurChar == '"') {
309 StrVal.assign(Start, CurPtr-1);
310 UnEscapeLexed(StrVal);
316 /// ReadVarName - Read the rest of a token containing a variable name.
317 bool LLLexer::ReadVarName() {
318 const char *NameStart = CurPtr;
319 if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
320 CurPtr[0] == '.' || CurPtr[0] == '_') {
322 while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
323 CurPtr[0] == '.' || CurPtr[0] == '_')
326 StrVal.assign(NameStart, CurPtr);
332 /// LexPercent - Lex all tokens that start with a % character:
333 /// LocalVar ::= %\"[^\"]*\"
334 /// LocalVar ::= %[-a-zA-Z$._][-a-zA-Z$._0-9]*
335 /// LocalVarID ::= %[0-9]+
336 lltok::Kind LLLexer::LexPercent() {
337 // Handle LocalVarName: %\"[^\"]*\"
338 if (CurPtr[0] == '"') {
340 return ReadString(lltok::LocalVar);
343 // Handle LocalVarName: %[-a-zA-Z$._][-a-zA-Z$._0-9]*
345 return lltok::LocalVar;
347 // Handle LocalVarID: %[0-9]+
348 if (isdigit(CurPtr[0])) {
349 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
352 uint64_t Val = atoull(TokStart+1, CurPtr);
353 if ((unsigned)Val != Val)
354 Error("invalid value number (too large)!");
355 UIntVal = unsigned(Val);
356 return lltok::LocalVarID;
362 /// LexQuote - Lex all tokens that start with a " character:
363 /// QuoteLabel "[^"]+":
364 /// StringConstant "[^"]*"
365 lltok::Kind LLLexer::LexQuote() {
366 lltok::Kind kind = ReadString(lltok::StringConstant);
367 if (kind == lltok::Error || kind == lltok::Eof)
370 if (CurPtr[0] == ':') {
372 kind = lltok::LabelStr;
381 lltok::Kind LLLexer::LexExclaim() {
382 // Lex a metadata name as a MetadataVar.
383 if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
384 CurPtr[0] == '.' || CurPtr[0] == '_' || CurPtr[0] == '\\') {
386 while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
387 CurPtr[0] == '.' || CurPtr[0] == '_' || CurPtr[0] == '\\')
390 StrVal.assign(TokStart+1, CurPtr); // Skip !
391 UnEscapeLexed(StrVal);
392 return lltok::MetadataVar;
394 return lltok::exclaim;
397 /// LexIdentifier: Handle several related productions:
398 /// Label [-a-zA-Z$._0-9]+:
399 /// IntegerType i[0-9]+
400 /// Keyword sdiv, float, ...
401 /// HexIntConstant [us]0x[0-9A-Fa-f]+
402 lltok::Kind LLLexer::LexIdentifier() {
403 const char *StartChar = CurPtr;
404 const char *IntEnd = CurPtr[-1] == 'i' ? 0 : StartChar;
405 const char *KeywordEnd = 0;
407 for (; isLabelChar(*CurPtr); ++CurPtr) {
408 // If we decide this is an integer, remember the end of the sequence.
409 if (!IntEnd && !isdigit(*CurPtr)) IntEnd = CurPtr;
410 if (!KeywordEnd && !isalnum(*CurPtr) && *CurPtr != '_') KeywordEnd = CurPtr;
413 // If we stopped due to a colon, this really is a label.
414 if (*CurPtr == ':') {
415 StrVal.assign(StartChar-1, CurPtr++);
416 return lltok::LabelStr;
419 // Otherwise, this wasn't a label. If this was valid as an integer type,
421 if (IntEnd == 0) IntEnd = CurPtr;
422 if (IntEnd != StartChar) {
424 uint64_t NumBits = atoull(StartChar, CurPtr);
425 if (NumBits < IntegerType::MIN_INT_BITS ||
426 NumBits > IntegerType::MAX_INT_BITS) {
427 Error("bitwidth for integer type out of range!");
430 TyVal = IntegerType::get(Context, NumBits);
434 // Otherwise, this was a letter sequence. See which keyword this is.
435 if (KeywordEnd == 0) KeywordEnd = CurPtr;
438 unsigned Len = CurPtr-StartChar;
439 #define KEYWORD(STR) \
440 if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) \
441 return lltok::kw_##STR;
443 KEYWORD(true); KEYWORD(false);
444 KEYWORD(declare); KEYWORD(define);
445 KEYWORD(global); KEYWORD(constant);
448 KEYWORD(linker_private);
449 KEYWORD(linker_private_weak);
450 KEYWORD(linker_private_weak_def_auto); // FIXME: For backwards compatibility.
452 KEYWORD(available_externally);
454 KEYWORD(linkonce_odr);
455 KEYWORD(linkonce_odr_auto_hide);
465 KEYWORD(unnamed_addr);
466 KEYWORD(extern_weak);
468 KEYWORD(thread_local);
469 KEYWORD(localdynamic);
470 KEYWORD(initialexec);
472 KEYWORD(zeroinitializer);
480 KEYWORD(deplibs); // FIXME: Remove in 4.0.
490 KEYWORD(singlethread);
509 KEYWORD(inteldialect);
515 KEYWORD(x86_stdcallcc);
516 KEYWORD(x86_fastcallcc);
517 KEYWORD(x86_thiscallcc);
519 KEYWORD(arm_aapcscc);
520 KEYWORD(arm_aapcs_vfpcc);
521 KEYWORD(msp430_intrcc);
524 KEYWORD(spir_kernel);
526 KEYWORD(intel_ocl_bicc);
544 KEYWORD(returns_twice);
548 KEYWORD(alwaysinline);
553 KEYWORD(noimplicitfloat);
555 KEYWORD(nonlazybind);
556 KEYWORD(address_safety);
558 KEYWORD(noduplicate);
563 KEYWORD(eq); KEYWORD(ne); KEYWORD(slt); KEYWORD(sgt); KEYWORD(sle);
564 KEYWORD(sge); KEYWORD(ult); KEYWORD(ugt); KEYWORD(ule); KEYWORD(uge);
565 KEYWORD(oeq); KEYWORD(one); KEYWORD(olt); KEYWORD(ogt); KEYWORD(ole);
566 KEYWORD(oge); KEYWORD(ord); KEYWORD(uno); KEYWORD(ueq); KEYWORD(une);
568 KEYWORD(xchg); KEYWORD(nand); KEYWORD(max); KEYWORD(min); KEYWORD(umax);
572 KEYWORD(blockaddress);
574 KEYWORD(personality);
580 // Keywords for types.
581 #define TYPEKEYWORD(STR, LLVMTY) \
582 if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
583 TyVal = LLVMTY; return lltok::Type; }
584 TYPEKEYWORD("void", Type::getVoidTy(Context));
585 TYPEKEYWORD("half", Type::getHalfTy(Context));
586 TYPEKEYWORD("float", Type::getFloatTy(Context));
587 TYPEKEYWORD("double", Type::getDoubleTy(Context));
588 TYPEKEYWORD("x86_fp80", Type::getX86_FP80Ty(Context));
589 TYPEKEYWORD("fp128", Type::getFP128Ty(Context));
590 TYPEKEYWORD("ppc_fp128", Type::getPPC_FP128Ty(Context));
591 TYPEKEYWORD("label", Type::getLabelTy(Context));
592 TYPEKEYWORD("metadata", Type::getMetadataTy(Context));
593 TYPEKEYWORD("x86_mmx", Type::getX86_MMXTy(Context));
596 // Keywords for instructions.
597 #define INSTKEYWORD(STR, Enum) \
598 if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) { \
599 UIntVal = Instruction::Enum; return lltok::kw_##STR; }
601 INSTKEYWORD(add, Add); INSTKEYWORD(fadd, FAdd);
602 INSTKEYWORD(sub, Sub); INSTKEYWORD(fsub, FSub);
603 INSTKEYWORD(mul, Mul); INSTKEYWORD(fmul, FMul);
604 INSTKEYWORD(udiv, UDiv); INSTKEYWORD(sdiv, SDiv); INSTKEYWORD(fdiv, FDiv);
605 INSTKEYWORD(urem, URem); INSTKEYWORD(srem, SRem); INSTKEYWORD(frem, FRem);
606 INSTKEYWORD(shl, Shl); INSTKEYWORD(lshr, LShr); INSTKEYWORD(ashr, AShr);
607 INSTKEYWORD(and, And); INSTKEYWORD(or, Or); INSTKEYWORD(xor, Xor);
608 INSTKEYWORD(icmp, ICmp); INSTKEYWORD(fcmp, FCmp);
610 INSTKEYWORD(phi, PHI);
611 INSTKEYWORD(call, Call);
612 INSTKEYWORD(trunc, Trunc);
613 INSTKEYWORD(zext, ZExt);
614 INSTKEYWORD(sext, SExt);
615 INSTKEYWORD(fptrunc, FPTrunc);
616 INSTKEYWORD(fpext, FPExt);
617 INSTKEYWORD(uitofp, UIToFP);
618 INSTKEYWORD(sitofp, SIToFP);
619 INSTKEYWORD(fptoui, FPToUI);
620 INSTKEYWORD(fptosi, FPToSI);
621 INSTKEYWORD(inttoptr, IntToPtr);
622 INSTKEYWORD(ptrtoint, PtrToInt);
623 INSTKEYWORD(bitcast, BitCast);
624 INSTKEYWORD(select, Select);
625 INSTKEYWORD(va_arg, VAArg);
626 INSTKEYWORD(ret, Ret);
628 INSTKEYWORD(switch, Switch);
629 INSTKEYWORD(indirectbr, IndirectBr);
630 INSTKEYWORD(invoke, Invoke);
631 INSTKEYWORD(resume, Resume);
632 INSTKEYWORD(unreachable, Unreachable);
634 INSTKEYWORD(alloca, Alloca);
635 INSTKEYWORD(load, Load);
636 INSTKEYWORD(store, Store);
637 INSTKEYWORD(cmpxchg, AtomicCmpXchg);
638 INSTKEYWORD(atomicrmw, AtomicRMW);
639 INSTKEYWORD(fence, Fence);
640 INSTKEYWORD(getelementptr, GetElementPtr);
642 INSTKEYWORD(extractelement, ExtractElement);
643 INSTKEYWORD(insertelement, InsertElement);
644 INSTKEYWORD(shufflevector, ShuffleVector);
645 INSTKEYWORD(extractvalue, ExtractValue);
646 INSTKEYWORD(insertvalue, InsertValue);
647 INSTKEYWORD(landingpad, LandingPad);
650 // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
651 // the CFE to avoid forcing it to deal with 64-bit numbers.
652 if ((TokStart[0] == 'u' || TokStart[0] == 's') &&
653 TokStart[1] == '0' && TokStart[2] == 'x' && isxdigit(TokStart[3])) {
654 int len = CurPtr-TokStart-3;
655 uint32_t bits = len * 4;
656 APInt Tmp(bits, StringRef(TokStart+3, len), 16);
657 uint32_t activeBits = Tmp.getActiveBits();
658 if (activeBits > 0 && activeBits < bits)
659 Tmp = Tmp.trunc(activeBits);
660 APSIntVal = APSInt(Tmp, TokStart[0] == 'u');
661 return lltok::APSInt;
664 // If this is "cc1234", return this as just "cc".
665 if (TokStart[0] == 'c' && TokStart[1] == 'c') {
670 // Finally, if this isn't known, return an error.
676 /// Lex0x: Handle productions that start with 0x, knowing that it matches and
677 /// that this is not a label:
678 /// HexFPConstant 0x[0-9A-Fa-f]+
679 /// HexFP80Constant 0xK[0-9A-Fa-f]+
680 /// HexFP128Constant 0xL[0-9A-Fa-f]+
681 /// HexPPC128Constant 0xM[0-9A-Fa-f]+
682 /// HexHalfConstant 0xH[0-9A-Fa-f]+
683 lltok::Kind LLLexer::Lex0x() {
684 CurPtr = TokStart + 2;
687 if ((CurPtr[0] >= 'K' && CurPtr[0] <= 'M') || CurPtr[0] == 'H') {
693 if (!isxdigit(CurPtr[0])) {
694 // Bad token, return it as an error.
699 while (isxdigit(CurPtr[0]))
703 // HexFPConstant - Floating point constant represented in IEEE format as a
704 // hexadecimal number for when exponential notation is not precise enough.
705 // Half, Float, and double only.
706 APFloatVal = APFloat(BitsToDouble(HexIntToVal(TokStart+2, CurPtr)));
707 return lltok::APFloat;
712 default: llvm_unreachable("Unknown kind!");
714 // F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
715 FP80HexToIntPair(TokStart+3, CurPtr, Pair);
716 APFloatVal = APFloat(APFloat::x87DoubleExtended, APInt(80, Pair));
717 return lltok::APFloat;
719 // F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
720 HexToIntPair(TokStart+3, CurPtr, Pair);
721 APFloatVal = APFloat(APFloat::IEEEquad, APInt(128, Pair));
722 return lltok::APFloat;
724 // PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
725 HexToIntPair(TokStart+3, CurPtr, Pair);
726 APFloatVal = APFloat(APFloat::PPCDoubleDouble, APInt(128, Pair));
727 return lltok::APFloat;
729 APFloatVal = APFloat(APFloat::IEEEhalf,
730 APInt(16,HexIntToVal(TokStart+3, CurPtr)));
731 return lltok::APFloat;
735 /// LexIdentifier: Handle several related productions:
736 /// Label [-a-zA-Z$._0-9]+:
738 /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
740 /// HexFPConstant 0x[0-9A-Fa-f]+
741 /// HexFP80Constant 0xK[0-9A-Fa-f]+
742 /// HexFP128Constant 0xL[0-9A-Fa-f]+
743 /// HexPPC128Constant 0xM[0-9A-Fa-f]+
744 lltok::Kind LLLexer::LexDigitOrNegative() {
745 // If the letter after the negative is not a number, this is probably a label.
746 if (!isdigit(TokStart[0]) && !isdigit(CurPtr[0])) {
747 // Okay, this is not a number after the -, it's probably a label.
748 if (const char *End = isLabelTail(CurPtr)) {
749 StrVal.assign(TokStart, End-1);
751 return lltok::LabelStr;
757 // At this point, it is either a label, int or fp constant.
759 // Skip digits, we have at least one.
760 for (; isdigit(CurPtr[0]); ++CurPtr)
763 // Check to see if this really is a label afterall, e.g. "-1:".
764 if (isLabelChar(CurPtr[0]) || CurPtr[0] == ':') {
765 if (const char *End = isLabelTail(CurPtr)) {
766 StrVal.assign(TokStart, End-1);
768 return lltok::LabelStr;
772 // If the next character is a '.', then it is a fp value, otherwise its
774 if (CurPtr[0] != '.') {
775 if (TokStart[0] == '0' && TokStart[1] == 'x')
777 unsigned Len = CurPtr-TokStart;
778 uint32_t numBits = ((Len * 64) / 19) + 2;
779 APInt Tmp(numBits, StringRef(TokStart, Len), 10);
780 if (TokStart[0] == '-') {
781 uint32_t minBits = Tmp.getMinSignedBits();
782 if (minBits > 0 && minBits < numBits)
783 Tmp = Tmp.trunc(minBits);
784 APSIntVal = APSInt(Tmp, false);
786 uint32_t activeBits = Tmp.getActiveBits();
787 if (activeBits > 0 && activeBits < numBits)
788 Tmp = Tmp.trunc(activeBits);
789 APSIntVal = APSInt(Tmp, true);
791 return lltok::APSInt;
796 // Skip over [0-9]*([eE][-+]?[0-9]+)?
797 while (isdigit(CurPtr[0])) ++CurPtr;
799 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
800 if (isdigit(CurPtr[1]) ||
801 ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
803 while (isdigit(CurPtr[0])) ++CurPtr;
807 APFloatVal = APFloat(std::atof(TokStart));
808 return lltok::APFloat;
811 /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
812 lltok::Kind LLLexer::LexPositive() {
813 // If the letter after the negative is a number, this is probably not a
815 if (!isdigit(CurPtr[0]))
819 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
822 // At this point, we need a '.'.
823 if (CurPtr[0] != '.') {
830 // Skip over [0-9]*([eE][-+]?[0-9]+)?
831 while (isdigit(CurPtr[0])) ++CurPtr;
833 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
834 if (isdigit(CurPtr[1]) ||
835 ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
837 while (isdigit(CurPtr[0])) ++CurPtr;
841 APFloatVal = APFloat(std::atof(TokStart));
842 return lltok::APFloat;