1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

Add support for hexadecimal FP constants!

llvm-svn: 2135
This commit is contained in:
Chris Lattner 2002-04-07 08:10:41 +00:00
parent e7b5d159c5
commit c6c7c99011

View File

@ -19,9 +19,6 @@
%{
#include "ParserInternals.h"
#include "llvm/BasicBlock.h"
#include "llvm/Method.h"
#include "llvm/Module.h"
#include <list>
#include "llvmAsmParser.h"
#include <ctype.h>
@ -39,19 +36,45 @@
// long representation... this does not have to do input error checking,
// because we know that the input will be matched by a suitable regex...
//
uint64_t atoull(const char *Buffer) {
static uint64_t atoull(const char *Buffer) {
uint64_t Result = 0;
for (; *Buffer; Buffer++) {
uint64_t OldRes = Result;
Result *= 10;
Result += *Buffer-'0';
if (Result < OldRes) { // Uh, oh, overflow detected!!!
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 = 0;
for (; *Buffer; ++Buffer) {
uint64_t OldRes = Result;
Result *= 16;
char C = *Buffer;
if (C >= '0' && C <= '9')
Result += C-'0';
else if (C >= 'A' && C <= 'F')
Result += C-'A'+10;
else if (C >= 'a' && C <= 'f')
Result += C-'a'+10;
if (Result < OldRes) // Uh, oh, overflow detected!!!
ThrowException("constant bigger than 64 bits detected!");
}
assert(sizeof(double) == sizeof(Result) &&
"Data sizes incompatible on this target!");
void *ProxyPointer = &Result; // Break TBAA correctly
cerr << "VALUE: " << *(double*)ProxyPointer << "\n";
return *(double*)ProxyPointer; // Cast Hex constant to double
}
// UnEscapeLexed - Run through the specified buffer and change \xx codes to the
// appropriate character. If AllowNull is set to false, a \00 value will cause
@ -110,9 +133,13 @@ PInteger [0-9]+
NInteger -[0-9]+
/* FPConstant - A Floating point constant.
TODO: Expand lexer to support 10e50 FP constant notation */
*/
FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
/* HexFPConstant - Floating point constant represented in IEEE format as a
* hexadecimal number for when exponential notation is not precise enough.
*/
HexFPConstant 0x[0-9A-Fa-f]+
%%
{Comment} { /* Ignore comments for now */ }
@ -233,6 +260,7 @@ getelementptr { RET_TOK(MemOpVal, GetElementPtr, GETELEMENTPTR); }
}
{FPConstant} { llvmAsmlval.FPVal = atof(yytext); return FPVAL; }
{HexFPConstant} { llvmAsmlval.FPVal = HexToFP(yytext); return FPVAL; }
[ \t\n] { /* Ignore whitespace */ }
. { return yytext[0]; }