Print out 'float' constants correctly
authorChris Lattner <sabre@nondot.org>
Thu, 7 Nov 2002 19:43:59 +0000 (19:43 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 7 Nov 2002 19:43:59 +0000 (19:43 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4607 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/CBackend/CBackend.cpp
lib/Target/CBackend/Writer.cpp

index 0e274c70cc0c6b00942b362cb60f381b2c9646c0..3a0fbe99b9b32b204f82f14747ce762dad2cdc11 100644 (file)
@@ -535,6 +535,7 @@ void CWriter::printModule(Module *M) {
 
       << "\n\n/* Support for floating point constants */\n"
       << "typedef unsigned long long ConstantDoubleTy;\n"
+      << "typedef unsigned int        ConstantFloatTy;\n"
 
       << "\n\n/* Global Declarations */\n";
 
@@ -772,9 +773,17 @@ void CWriter::printFunction(Function *F) {
         double Val = FPC->getValue();
         
         FPConstantMap[FPC] = FPCounter;  // Number the FP constants
-        Out << "  const ConstantDoubleTy FloatConstant" << FPCounter++
-            << " = 0x" << std::hex << *(unsigned long long*)&Val << std::dec
-            << ";    /* " << Val << " */\n";
+
+        if (FPC->getType() == Type::DoubleTy)
+          Out << "  const ConstantDoubleTy FloatConstant" << FPCounter++
+              << " = 0x" << std::hex << *(unsigned long long*)&Val << std::dec
+              << ";    /* " << Val << " */\n";
+        else if (FPC->getType() == Type::FloatTy)
+          Out << "  const ConstantFloatTy FloatConstant" << FPCounter++
+              << " = 0x" << std::hex << *(unsigned*)&Val << std::dec
+              << ";    /* " << Val << " */\n";
+        else
+          assert(0 && "Unknown float type!");
       }
 
   Out << "\n";
index 0e274c70cc0c6b00942b362cb60f381b2c9646c0..3a0fbe99b9b32b204f82f14747ce762dad2cdc11 100644 (file)
@@ -535,6 +535,7 @@ void CWriter::printModule(Module *M) {
 
       << "\n\n/* Support for floating point constants */\n"
       << "typedef unsigned long long ConstantDoubleTy;\n"
+      << "typedef unsigned int        ConstantFloatTy;\n"
 
       << "\n\n/* Global Declarations */\n";
 
@@ -772,9 +773,17 @@ void CWriter::printFunction(Function *F) {
         double Val = FPC->getValue();
         
         FPConstantMap[FPC] = FPCounter;  // Number the FP constants
-        Out << "  const ConstantDoubleTy FloatConstant" << FPCounter++
-            << " = 0x" << std::hex << *(unsigned long long*)&Val << std::dec
-            << ";    /* " << Val << " */\n";
+
+        if (FPC->getType() == Type::DoubleTy)
+          Out << "  const ConstantDoubleTy FloatConstant" << FPCounter++
+              << " = 0x" << std::hex << *(unsigned long long*)&Val << std::dec
+              << ";    /* " << Val << " */\n";
+        else if (FPC->getType() == Type::FloatTy)
+          Out << "  const ConstantFloatTy FloatConstant" << FPCounter++
+              << " = 0x" << std::hex << *(unsigned*)&Val << std::dec
+              << ";    /* " << Val << " */\n";
+        else
+          assert(0 && "Unknown float type!");
       }
 
   Out << "\n";