From: Chris Lattner Date: Thu, 17 Apr 2003 22:17:32 +0000 (+0000) Subject: Allow hexadecimal integer constants to be used X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e8ba107507b698b96c7a8f6981182333cb76df6;p=llvm Allow hexadecimal integer constants to be used git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5802 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AsmParser/Lexer.l b/lib/AsmParser/Lexer.l index f342d2fe342..47c067ba8ce 100644 --- a/lib/AsmParser/Lexer.l +++ b/lib/AsmParser/Lexer.l @@ -48,10 +48,7 @@ static uint64_t atoull(const char *Buffer) { return Result; } -// HexToFP - Convert the ascii string in hexidecimal format to the floating -// point representation of it. -// -static double HexToFP(const char *Buffer) { +static uint64_t HexIntToVal(const char *Buffer) { uint64_t Result = 0; for (; *Buffer; ++Buffer) { uint64_t OldRes = Result; @@ -67,6 +64,15 @@ static double HexToFP(const char *Buffer) { if (Result < OldRes) // Uh, oh, overflow detected!!! ThrowException("constant bigger than 64 bits detected!"); } + return Result; +} + + +// HexToFP - Convert the ascii string in hexidecimal format to the floating +// point representation of it. +// +static double HexToFP(const char *Buffer) { + uint64_t Result = HexIntToVal(Buffer); assert(sizeof(double) == sizeof(Result) && "Data sizes incompatible on this target!"); @@ -142,6 +148,11 @@ FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)? * hexadecimal number for when exponential notation is not precise enough. */ HexFPConstant 0x[0-9A-Fa-f]+ + +/* HexIntConstant - Hexadecimal constant generated by the CFE to avoid forcing + * it to deal with 64 bit numbers. + */ +HexIntConstant [us]0x[0-9A-Fa-f]+ %% {Comment} { /* Ignore comments for now */ } @@ -249,7 +260,10 @@ getelementptr { RET_TOK(MemOpVal, GetElementPtr, GETELEMENTPTR); } llvmAsmlval.SInt64Val = -Val; return ESINT64VAL; } - +{HexIntConstant} { + llvmAsmlval.UInt64Val = HexIntToVal(yytext+3); + return yytext[0] == 's' ? ESINT64VAL : EUINT64VAL; + } {EPInteger} { llvmAsmlval.UIntVal = atoull(yytext+1); return UINTVAL; } {ENInteger} {