Added support symbolic floating point constants in the MC assembler for Infinity
authorKevin Enderby <enderby@apple.com>
Tue, 29 Mar 2011 21:11:52 +0000 (21:11 +0000)
committerKevin Enderby <enderby@apple.com>
Tue, 29 Mar 2011 21:11:52 +0000 (21:11 +0000)
and Nans with the same strings as GAS supports.  rdar://8673024

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128488 91177308-0d34-0410-b5e6-96231b3b80d8

lib/MC/MCParser/AsmParser.cpp
test/MC/AsmParser/floating-literals.s

index 19f7bd8959a2b073469d40d1ce7246eaa9fc5a73..ff5298fe1beb4ff82b21b9e862c52325f13ce05d 100644 (file)
@@ -1552,13 +1552,21 @@ bool AsmParser::ParseDirectiveRealValue(const fltSemantics &Semantics) {
         Lex();
 
       if (getLexer().isNot(AsmToken::Integer) &&
-          getLexer().isNot(AsmToken::Real))
+          getLexer().isNot(AsmToken::Real) &&
+          getLexer().isNot(AsmToken::Identifier))
         return TokError("unexpected token in directive");
 
       // Convert to an APFloat.
       APFloat Value(Semantics);
-      if (Value.convertFromString(getTok().getString(),
-                                  APFloat::rmNearestTiesToEven) ==
+      StringRef IDVal = getTok().getString();
+      if (getLexer().is(AsmToken::Identifier)) {
+        if (!IDVal.compare_lower("infinity") || !IDVal.compare_lower("inf"))
+          Value = APFloat::getInf(Semantics);
+        else if (!IDVal.compare_lower("nan"))
+          Value = APFloat::getNaN(Semantics, false, ~0);
+        else
+          return TokError("invalid floating point literal");
+      } else if (Value.convertFromString(IDVal, APFloat::rmNearestTiesToEven) ==
           APFloat::opInvalidOp)
         return TokError("invalid floating point literal");
       if (IsNeg)
index bd122a8cf0e34e6f6f9ec89c56756937a5f07e1e..0e96571e1acaced08de9e20a6c338c609fdfecf9 100644 (file)
@@ -6,6 +6,12 @@
 # CHECK: .long 1082549862
 .single 1.2455, +2.3, 3, + 4.2
 
+# CHECK: .long 2139095040
+.single InFinIty
+
+# CHECK: .long 2147483647
+.single nAN
+
 # CHECK: .long  1067928519
 .float 1.307