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(externally_initialized);
467 KEYWORD(extern_weak);
469 KEYWORD(thread_local);
470 KEYWORD(localdynamic);
471 KEYWORD(initialexec);
473 KEYWORD(zeroinitializer);
481 KEYWORD(deplibs); // FIXME: Remove in 4.0.
491 KEYWORD(singlethread);
510 KEYWORD(inteldialect);
516 KEYWORD(x86_stdcallcc);
517 KEYWORD(x86_fastcallcc);
518 KEYWORD(x86_thiscallcc);
520 KEYWORD(arm_aapcscc);
521 KEYWORD(arm_aapcs_vfpcc);
522 KEYWORD(msp430_intrcc);
525 KEYWORD(spir_kernel);
527 KEYWORD(intel_ocl_bicc);
545 KEYWORD(returns_twice);
549 KEYWORD(alwaysinline);
555 KEYWORD(noimplicitfloat);
557 KEYWORD(nonlazybind);
558 KEYWORD(address_safety);
560 KEYWORD(noduplicate);
565 KEYWORD(eq); KEYWORD(ne); KEYWORD(slt); KEYWORD(sgt); KEYWORD(sle);
566 KEYWORD(sge); KEYWORD(ult); KEYWORD(ugt); KEYWORD(ule); KEYWORD(uge);
567 KEYWORD(oeq); KEYWORD(one); KEYWORD(olt); KEYWORD(ogt); KEYWORD(ole);
568 KEYWORD(oge); KEYWORD(ord); KEYWORD(uno); KEYWORD(ueq); KEYWORD(une);
570 KEYWORD(xchg); KEYWORD(nand); KEYWORD(max); KEYWORD(min); KEYWORD(umax);
574 KEYWORD(blockaddress);
576 KEYWORD(personality);
582 // Keywords for types.
583 #define TYPEKEYWORD(STR, LLVMTY) \
584 if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
585 TyVal = LLVMTY; return lltok::Type; }
586 TYPEKEYWORD("void", Type::getVoidTy(Context));
587 TYPEKEYWORD("half", Type::getHalfTy(Context));
588 TYPEKEYWORD("float", Type::getFloatTy(Context));
589 TYPEKEYWORD("double", Type::getDoubleTy(Context));
590 TYPEKEYWORD("x86_fp80", Type::getX86_FP80Ty(Context));
591 TYPEKEYWORD("fp128", Type::getFP128Ty(Context));
592 TYPEKEYWORD("ppc_fp128", Type::getPPC_FP128Ty(Context));
593 TYPEKEYWORD("label", Type::getLabelTy(Context));
594 TYPEKEYWORD("metadata", Type::getMetadataTy(Context));
595 TYPEKEYWORD("x86_mmx", Type::getX86_MMXTy(Context));
598 // Keywords for instructions.
599 #define INSTKEYWORD(STR, Enum) \
600 if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) { \
601 UIntVal = Instruction::Enum; return lltok::kw_##STR; }
603 INSTKEYWORD(add, Add); INSTKEYWORD(fadd, FAdd);
604 INSTKEYWORD(sub, Sub); INSTKEYWORD(fsub, FSub);
605 INSTKEYWORD(mul, Mul); INSTKEYWORD(fmul, FMul);
606 INSTKEYWORD(udiv, UDiv); INSTKEYWORD(sdiv, SDiv); INSTKEYWORD(fdiv, FDiv);
607 INSTKEYWORD(urem, URem); INSTKEYWORD(srem, SRem); INSTKEYWORD(frem, FRem);
608 INSTKEYWORD(shl, Shl); INSTKEYWORD(lshr, LShr); INSTKEYWORD(ashr, AShr);
609 INSTKEYWORD(and, And); INSTKEYWORD(or, Or); INSTKEYWORD(xor, Xor);
610 INSTKEYWORD(icmp, ICmp); INSTKEYWORD(fcmp, FCmp);
612 INSTKEYWORD(phi, PHI);
613 INSTKEYWORD(call, Call);
614 INSTKEYWORD(trunc, Trunc);
615 INSTKEYWORD(zext, ZExt);
616 INSTKEYWORD(sext, SExt);
617 INSTKEYWORD(fptrunc, FPTrunc);
618 INSTKEYWORD(fpext, FPExt);
619 INSTKEYWORD(uitofp, UIToFP);
620 INSTKEYWORD(sitofp, SIToFP);
621 INSTKEYWORD(fptoui, FPToUI);
622 INSTKEYWORD(fptosi, FPToSI);
623 INSTKEYWORD(inttoptr, IntToPtr);
624 INSTKEYWORD(ptrtoint, PtrToInt);
625 INSTKEYWORD(bitcast, BitCast);
626 INSTKEYWORD(select, Select);
627 INSTKEYWORD(va_arg, VAArg);
628 INSTKEYWORD(ret, Ret);
630 INSTKEYWORD(switch, Switch);
631 INSTKEYWORD(indirectbr, IndirectBr);
632 INSTKEYWORD(invoke, Invoke);
633 INSTKEYWORD(resume, Resume);
634 INSTKEYWORD(unreachable, Unreachable);
636 INSTKEYWORD(alloca, Alloca);
637 INSTKEYWORD(load, Load);
638 INSTKEYWORD(store, Store);
639 INSTKEYWORD(cmpxchg, AtomicCmpXchg);
640 INSTKEYWORD(atomicrmw, AtomicRMW);
641 INSTKEYWORD(fence, Fence);
642 INSTKEYWORD(getelementptr, GetElementPtr);
644 INSTKEYWORD(extractelement, ExtractElement);
645 INSTKEYWORD(insertelement, InsertElement);
646 INSTKEYWORD(shufflevector, ShuffleVector);
647 INSTKEYWORD(extractvalue, ExtractValue);
648 INSTKEYWORD(insertvalue, InsertValue);
649 INSTKEYWORD(landingpad, LandingPad);
652 // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
653 // the CFE to avoid forcing it to deal with 64-bit numbers.
654 if ((TokStart[0] == 'u' || TokStart[0] == 's') &&
655 TokStart[1] == '0' && TokStart[2] == 'x' && isxdigit(TokStart[3])) {
656 int len = CurPtr-TokStart-3;
657 uint32_t bits = len * 4;
658 APInt Tmp(bits, StringRef(TokStart+3, len), 16);
659 uint32_t activeBits = Tmp.getActiveBits();
660 if (activeBits > 0 && activeBits < bits)
661 Tmp = Tmp.trunc(activeBits);
662 APSIntVal = APSInt(Tmp, TokStart[0] == 'u');
663 return lltok::APSInt;
666 // If this is "cc1234", return this as just "cc".
667 if (TokStart[0] == 'c' && TokStart[1] == 'c') {
672 // Finally, if this isn't known, return an error.
678 /// Lex0x: Handle productions that start with 0x, knowing that it matches and
679 /// that this is not a label:
680 /// HexFPConstant 0x[0-9A-Fa-f]+
681 /// HexFP80Constant 0xK[0-9A-Fa-f]+
682 /// HexFP128Constant 0xL[0-9A-Fa-f]+
683 /// HexPPC128Constant 0xM[0-9A-Fa-f]+
684 /// HexHalfConstant 0xH[0-9A-Fa-f]+
685 lltok::Kind LLLexer::Lex0x() {
686 CurPtr = TokStart + 2;
689 if ((CurPtr[0] >= 'K' && CurPtr[0] <= 'M') || CurPtr[0] == 'H') {
695 if (!isxdigit(CurPtr[0])) {
696 // Bad token, return it as an error.
701 while (isxdigit(CurPtr[0]))
705 // HexFPConstant - Floating point constant represented in IEEE format as a
706 // hexadecimal number for when exponential notation is not precise enough.
707 // Half, Float, and double only.
708 APFloatVal = APFloat(BitsToDouble(HexIntToVal(TokStart+2, CurPtr)));
709 return lltok::APFloat;
714 default: llvm_unreachable("Unknown kind!");
716 // F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
717 FP80HexToIntPair(TokStart+3, CurPtr, Pair);
718 APFloatVal = APFloat(APFloat::x87DoubleExtended, APInt(80, Pair));
719 return lltok::APFloat;
721 // F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
722 HexToIntPair(TokStart+3, CurPtr, Pair);
723 APFloatVal = APFloat(APFloat::IEEEquad, APInt(128, Pair));
724 return lltok::APFloat;
726 // PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
727 HexToIntPair(TokStart+3, CurPtr, Pair);
728 APFloatVal = APFloat(APFloat::PPCDoubleDouble, APInt(128, Pair));
729 return lltok::APFloat;
731 APFloatVal = APFloat(APFloat::IEEEhalf,
732 APInt(16,HexIntToVal(TokStart+3, CurPtr)));
733 return lltok::APFloat;
737 /// LexIdentifier: Handle several related productions:
738 /// Label [-a-zA-Z$._0-9]+:
740 /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
742 /// HexFPConstant 0x[0-9A-Fa-f]+
743 /// HexFP80Constant 0xK[0-9A-Fa-f]+
744 /// HexFP128Constant 0xL[0-9A-Fa-f]+
745 /// HexPPC128Constant 0xM[0-9A-Fa-f]+
746 lltok::Kind LLLexer::LexDigitOrNegative() {
747 // If the letter after the negative is not a number, this is probably a label.
748 if (!isdigit(TokStart[0]) && !isdigit(CurPtr[0])) {
749 // Okay, this is not a number after the -, it's probably a label.
750 if (const char *End = isLabelTail(CurPtr)) {
751 StrVal.assign(TokStart, End-1);
753 return lltok::LabelStr;
759 // At this point, it is either a label, int or fp constant.
761 // Skip digits, we have at least one.
762 for (; isdigit(CurPtr[0]); ++CurPtr)
765 // Check to see if this really is a label afterall, e.g. "-1:".
766 if (isLabelChar(CurPtr[0]) || CurPtr[0] == ':') {
767 if (const char *End = isLabelTail(CurPtr)) {
768 StrVal.assign(TokStart, End-1);
770 return lltok::LabelStr;
774 // If the next character is a '.', then it is a fp value, otherwise its
776 if (CurPtr[0] != '.') {
777 if (TokStart[0] == '0' && TokStart[1] == 'x')
779 unsigned Len = CurPtr-TokStart;
780 uint32_t numBits = ((Len * 64) / 19) + 2;
781 APInt Tmp(numBits, StringRef(TokStart, Len), 10);
782 if (TokStart[0] == '-') {
783 uint32_t minBits = Tmp.getMinSignedBits();
784 if (minBits > 0 && minBits < numBits)
785 Tmp = Tmp.trunc(minBits);
786 APSIntVal = APSInt(Tmp, false);
788 uint32_t activeBits = Tmp.getActiveBits();
789 if (activeBits > 0 && activeBits < numBits)
790 Tmp = Tmp.trunc(activeBits);
791 APSIntVal = APSInt(Tmp, true);
793 return lltok::APSInt;
798 // Skip over [0-9]*([eE][-+]?[0-9]+)?
799 while (isdigit(CurPtr[0])) ++CurPtr;
801 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
802 if (isdigit(CurPtr[1]) ||
803 ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
805 while (isdigit(CurPtr[0])) ++CurPtr;
809 APFloatVal = APFloat(std::atof(TokStart));
810 return lltok::APFloat;
813 /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
814 lltok::Kind LLLexer::LexPositive() {
815 // If the letter after the negative is a number, this is probably not a
817 if (!isdigit(CurPtr[0]))
821 for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
824 // At this point, we need a '.'.
825 if (CurPtr[0] != '.') {
832 // Skip over [0-9]*([eE][-+]?[0-9]+)?
833 while (isdigit(CurPtr[0])) ++CurPtr;
835 if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
836 if (isdigit(CurPtr[1]) ||
837 ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
839 while (isdigit(CurPtr[0])) ++CurPtr;
843 APFloatVal = APFloat(std::atof(TokStart));
844 return lltok::APFloat;