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) {
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;
66 if (Result < OldRes) {
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);
83 for (
int i=0; i<16 && Buffer != End; i++, Buffer++) {
88 Error(
"constant bigger than 128 bits detected!");
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);
102 for (
int i=0; i<16; i++, Buffer++) {
107 Error(
"constant bigger than 128 bits detected!");
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] ==
'\\') {
122 }
else if (BIn < EndBuffer-2 &&
123 isxdigit(static_cast<unsigned char>(BIn[1])) &&
124 isxdigit(static_cast<unsigned char>(BIn[2]))) {
135 Str.resize(BOut-Buffer);
140 return isalnum(static_cast<unsigned char>(C)) || C ==
'-' || C ==
'$' ||
141 C ==
'.' || C ==
'_';
148 if (CurPtr[0] ==
':')
return CurPtr+1;
162 : CurBuf(StartBuf), ErrorInfo(Err), SM(sm), Context(C), APFloatVal(0.0) {
170 int LLLexer::getNextChar() {
171 char CurChar = *CurPtr++;
173 default:
return (
unsigned char)CurChar;
190 int CurChar = getNextChar();
194 if (isalpha(static_cast<unsigned char>(CurChar)) || CurChar ==
'_')
195 return LexIdentifier();
206 case '+':
return LexPositive();
207 case '@':
return LexAt();
208 case '%':
return LexPercent();
209 case '"':
return LexQuote();
213 StrVal.assign(TokStart, CurPtr-1);
216 if (CurPtr[0] ==
'.' && CurPtr[1] ==
'.') {
224 StrVal.assign(TokStart, CurPtr-1);
231 case '!':
return LexExclaim();
232 case '#':
return LexHash();
233 case '0':
case '1':
case '2':
case '3':
case '4':
234 case '5':
case '6':
case '7':
case '8':
case '9':
236 return LexDigitOrNegative();
252 void LLLexer::SkipLineComment() {
254 if (CurPtr[0] ==
'\n' || CurPtr[0] ==
'\r' || getNextChar() == EOF)
265 if (CurPtr[0] ==
'"') {
269 int CurChar = getNextChar();
271 if (CurChar == EOF) {
272 Error(
"end of file in global variable name");
275 if (CurChar ==
'"') {
276 StrVal.assign(TokStart+2, CurPtr-1);
288 if (
isdigit(static_cast<unsigned char>(CurPtr[0]))) {
289 for (++CurPtr;
isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
292 uint64_t Val = atoull(TokStart+1, CurPtr);
293 if ((
unsigned)Val != Val)
294 Error(
"invalid value number (too large)!");
304 const char *Start = CurPtr;
306 int CurChar = getNextChar();
308 if (CurChar == EOF) {
309 Error(
"end of file in string constant");
312 if (CurChar ==
'"') {
313 StrVal.assign(Start, CurPtr-1);
321 bool LLLexer::ReadVarName() {
322 const char *NameStart = CurPtr;
323 if (isalpha(static_cast<unsigned char>(CurPtr[0])) ||
324 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
325 CurPtr[0] ==
'.' || CurPtr[0] ==
'_') {
327 while (isalnum(static_cast<unsigned char>(CurPtr[0])) ||
328 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
329 CurPtr[0] ==
'.' || CurPtr[0] ==
'_')
332 StrVal.assign(NameStart, CurPtr);
344 if (CurPtr[0] ==
'"') {
354 if (
isdigit(static_cast<unsigned char>(CurPtr[0]))) {
355 for (++CurPtr;
isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
358 uint64_t Val = atoull(TokStart+1, CurPtr);
359 if ((
unsigned)Val != Val)
360 Error(
"invalid value number (too large)!");
376 if (CurPtr[0] ==
':') {
389 if (isalpha(static_cast<unsigned char>(CurPtr[0])) ||
390 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
391 CurPtr[0] ==
'.' || CurPtr[0] ==
'_' || CurPtr[0] ==
'\\') {
393 while (isalnum(static_cast<unsigned char>(CurPtr[0])) ||
394 CurPtr[0] ==
'-' || CurPtr[0] ==
'$' ||
395 CurPtr[0] ==
'.' || CurPtr[0] ==
'_' || CurPtr[0] ==
'\\')
398 StrVal.assign(TokStart+1, CurPtr);
409 if (
isdigit(static_cast<unsigned char>(CurPtr[0]))) {
410 for (++CurPtr;
isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
413 uint64_t Val = atoull(TokStart+1, CurPtr);
414 if ((
unsigned)Val != Val)
415 Error(
"invalid value number (too large)!");
429 const char *StartChar = CurPtr;
430 const char *IntEnd = CurPtr[-1] ==
'i' ? 0 : StartChar;
431 const char *KeywordEnd = 0;
435 if (!IntEnd && !
isdigit(static_cast<unsigned char>(*CurPtr)))
437 if (!KeywordEnd && !isalnum(static_cast<unsigned char>(*CurPtr)) &&
443 if (*CurPtr ==
':') {
444 StrVal.assign(StartChar-1, CurPtr++);
450 if (IntEnd == 0) IntEnd = CurPtr;
451 if (IntEnd != StartChar) {
453 uint64_t NumBits = atoull(StartChar, CurPtr);
456 Error(
"bitwidth for integer type out of range!");
464 if (KeywordEnd == 0) KeywordEnd = CurPtr;
467 unsigned Len = CurPtr-StartChar;
468 #define KEYWORD(STR) \
470 if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) \
471 return lltok::kw_##STR; \
495 KEYWORD(externally_initialized);
625 #define TYPEKEYWORD(STR, LLVMTY) \
626 if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
627 TyVal = LLVMTY; return lltok::Type; }
641 #define INSTKEYWORD(STR, Enum) \
642 if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) { \
643 UIntVal = Instruction::Enum; return lltok::kw_##STR; }
697 if ((TokStart[0] ==
'u' || TokStart[0] ==
's') &&
698 TokStart[1] ==
'0' && TokStart[2] ==
'x' &&
699 isxdigit(static_cast<unsigned char>(TokStart[3]))) {
700 int len = CurPtr-TokStart-3;
701 uint32_t bits = len * 4;
703 uint32_t activeBits = Tmp.getActiveBits();
704 if (activeBits > 0 && activeBits < bits)
705 Tmp = Tmp.trunc(activeBits);
706 APSIntVal =
APSInt(Tmp, TokStart[0] ==
'u');
711 if (TokStart[0] ==
'c' && TokStart[1] ==
'c') {
730 CurPtr = TokStart + 2;
733 if ((CurPtr[0] >=
'K' && CurPtr[0] <=
'M') || CurPtr[0] ==
'H') {
739 if (!isxdigit(static_cast<unsigned char>(CurPtr[0]))) {
745 while (isxdigit(static_cast<unsigned char>(CurPtr[0])))
761 FP80HexToIntPair(TokStart+3, CurPtr, Pair);
766 HexToIntPair(TokStart+3, CurPtr, Pair);
771 HexToIntPair(TokStart+3, CurPtr, Pair);
776 APInt(16,HexIntToVal(TokStart+3, CurPtr)));
792 if (!
isdigit(static_cast<unsigned char>(TokStart[0])) &&
793 !
isdigit(static_cast<unsigned char>(CurPtr[0]))) {
796 StrVal.assign(TokStart, End-1);
807 for (;
isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
813 StrVal.assign(TokStart, End-1);
821 if (CurPtr[0] !=
'.') {
822 if (TokStart[0] ==
'0' && TokStart[1] ==
'x')
824 unsigned Len = CurPtr-TokStart;
825 uint32_t numBits = ((Len * 64) / 19) + 2;
827 if (TokStart[0] ==
'-') {
828 uint32_t minBits = Tmp.getMinSignedBits();
829 if (minBits > 0 && minBits < numBits)
830 Tmp = Tmp.trunc(minBits);
831 APSIntVal =
APSInt(Tmp,
false);
833 uint32_t activeBits = Tmp.getActiveBits();
834 if (activeBits > 0 && activeBits < numBits)
835 Tmp = Tmp.trunc(activeBits);
836 APSIntVal =
APSInt(Tmp,
true);
844 while (
isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
846 if (CurPtr[0] ==
'e' || CurPtr[0] ==
'E') {
847 if (
isdigit(static_cast<unsigned char>(CurPtr[1])) ||
848 ((CurPtr[1] ==
'-' || CurPtr[1] ==
'+') &&
849 isdigit(static_cast<unsigned char>(CurPtr[2])))) {
851 while (
isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
863 if (!
isdigit(static_cast<unsigned char>(CurPtr[0])))
867 for (++CurPtr;
isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
871 if (CurPtr[0] !=
'.') {
879 while (
isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
881 if (CurPtr[0] ==
'e' || CurPtr[0] ==
'E') {
882 if (
isdigit(static_cast<unsigned char>(CurPtr[1])) ||
883 ((CurPtr[1] ==
'-' || CurPtr[1] ==
'+') &&
884 isdigit(static_cast<unsigned char>(CurPtr[2])))) {
886 while (
isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
static Type * getDoubleTy(LLVMContext &C)
const char * getBufferStart() const
static const char * isLabelTail(const char *CurPtr)
isLabelTail - Return true if this pointer points to a valid end of a label.
static Type * getMetadataTy(LLVMContext &C)
static Type * getX86_MMXTy(LLVMContext &C)
static Type * getX86_FP80Ty(LLVMContext &C)
static const fltSemantics x87DoubleExtended
virtual const char * getBufferIdentifier() const
static Type * getFloatTy(LLVMContext &C)
APInt urem(const APInt &LHS, const APInt &RHS)
Function for unsigned remainder operation.
#define TYPEKEYWORD(STR, LLVMTY)
#define llvm_unreachable(msg)
double atof(const char *str);
static const fltSemantics IEEEquad
APInt umax(const APInt &A, const APInt &B)
Determine the larger of two APInts considered to be unsigned.
static ConstantInt * ExtractElement(Constant *V, Constant *Idx)
static Type * getPPC_FP128Ty(LLVMContext &C)
static bool isLabelChar(char C)
isLabelChar - Return true for [-a-zA-Z$._0-9].
APInt lshr(const APInt &LHS, unsigned shiftAmt)
Logical right-shift function.
static const APInt srem(const SCEVConstant *C1, const SCEVConstant *C2)
static Type * getLabelTy(LLVMContext &C)
static bool sub(uint64_t *dest, const uint64_t *x, const uint64_t *y, unsigned len)
Generalized subtraction of 64-bit integer arrays.
static void mul(uint64_t dest[], uint64_t x[], unsigned xlen, uint64_t y[], unsigned ylen)
Generalized multiplicate of integer arrays.
APInt udiv(const APInt &LHS, const APInt &RHS)
Unsigned division function for APInt.
Minimum number of bits that can be specified.
static bool add(uint64_t *dest, const uint64_t *x, const uint64_t *y, unsigned len)
General addition of 64-bit integer arrays.
APInt ashr(const APInt &LHS, unsigned shiftAmt)
Arithmetic right-shift function.
APInt Or(const APInt &LHS, const APInt &RHS)
Bitwise OR function for APInt.
APInt Xor(const APInt &LHS, const APInt &RHS)
Bitwise XOR function for APInt.
static Type * getVoidTy(LLVMContext &C)
bool Error(LocTy L, const Twine &Msg) const
LLLexer(MemoryBuffer *StartBuf, SourceMgr &SM, SMDiagnostic &, LLVMContext &C)
static const fltSemantics IEEEhalf
static Type * getFP128Ty(LLVMContext &C)
static const APInt sdiv(const SCEVConstant *C1, const SCEVConstant *C2)
static Type * getHalfTy(LLVMContext &C)
static IntegerType * get(LLVMContext &C, unsigned NumBits)
Get or create an IntegerType instance.
static const fltSemantics PPCDoubleDouble
APInt umin(const APInt &A, const APInt &B)
Determine the smaller of two APInts considered to be signed.
double BitsToDouble(uint64_t Bits)
Class for arbitrary precision integers.
APInt And(const APInt &LHS, const APInt &RHS)
Bitwise AND function for APInt.
std::string getFilename() const
Deduce function attributes
const char * getBufferEnd() const
static void UnEscapeLexed(std::string &Str)
static unsigned hexDigitValue(char C)
APInt shl(const APInt &LHS, unsigned shiftAmt)
Left-shift function.
SMDiagnostic GetMessage(SMLoc Loc, DiagKind Kind, const Twine &Msg, ArrayRef< SMRange > Ranges=None, ArrayRef< SMFixIt > FixIts=None) const
Represents a location in source code.
#define INSTKEYWORD(STR, Enum)