projects
/
ghc-hetmet.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
3aadff5
)
Fix handling of float literals in llvm BE
author
David Terei
<davidterei@gmail.com>
Tue, 22 Jun 2010 12:16:42 +0000
(12:16 +0000)
committer
David Terei
<davidterei@gmail.com>
Tue, 22 Jun 2010 12:16:42 +0000
(12:16 +0000)
compiler/llvmGen/Llvm/Types.hs
patch
|
blob
|
history
diff --git
a/compiler/llvmGen/Llvm/Types.hs
b/compiler/llvmGen/Llvm/Types.hs
index
ac909d1
..
19a441f
100644
(file)
--- a/
compiler/llvmGen/Llvm/Types.hs
+++ b/
compiler/llvmGen/Llvm/Types.hs
@@
-191,7
+191,9
@@
getPlainName (LMLitVar x ) = getLit x
-- | Print a literal value. No type.
getLit :: LlvmLit -> String
getLit (LMIntLit i _) = show ((fromInteger i)::Int)
-- | Print a literal value. No type.
getLit :: LlvmLit -> String
getLit (LMIntLit i _) = show ((fromInteger i)::Int)
-getLit (LMFloatLit r _) = dToStr r
+getLit (LMFloatLit r LMFloat ) = fToStr $ realToFrac r
+getLit (LMFloatLit r LMDouble) = dToStr r
+getLit f@(LMFloatLit _ _) = error $ "Can't print this float literal!" ++ show f
-- | Return the 'LlvmType' of the 'LlvmVar'
getVarType :: LlvmVar -> LlvmType
-- | Return the 'LlvmType' of the 'LlvmVar'
getVarType :: LlvmVar -> LlvmType
@@
-705,6
+707,14
@@
dToStr d
str = map toUpper $ concat . fixEndian . (map hex) $ bs
in "0x" ++ str
str = map toUpper $ concat . fixEndian . (map hex) $ bs
in "0x" ++ str
+-- | Convert a Haskell Float to an LLVM hex encoded floating point form.
+-- LLVM uses the same encoding for both floats and doubles (16 digit hex
+-- string) but floats must have the last half all zeroes so it can fit into
+-- a float size type.
+{-# NOINLINE fToStr #-}
+fToStr :: Float -> String
+fToStr = (dToStr . realToFrac)
+
-- | Reverse or leave byte data alone to fix endianness on this target.
fixEndian :: [a] -> [a]
#ifdef WORDS_BIGENDIAN
-- | Reverse or leave byte data alone to fix endianness on this target.
fixEndian :: [a] -> [a]
#ifdef WORDS_BIGENDIAN