]> granicus.if.org Git - llvm/commitdiff
Allow hexadecimal integer constants to be used
authorChris Lattner <sabre@nondot.org>
Thu, 17 Apr 2003 22:17:32 +0000 (22:17 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 17 Apr 2003 22:17:32 +0000 (22:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5802 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AsmParser/Lexer.l

index f342d2fe342288f78685e7d606b9413f9830fb5b..47c067ba8ce7e2736c03ac3b47464226362e1b30 100644 (file)
@@ -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}     {