summaryrefslogtreecommitdiff
path: root/compiler/utils/Fingerprint.hsc
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2011-07-12 10:41:22 +0100
committerSimon Marlow <marlowsd@gmail.com>2011-07-12 11:16:15 +0100
commit07ee15915d5a0d6d1aeee137541eec6e9c153e65 (patch)
tree6196e7fb0028798f957559135a1ec2ba5b22fd82 /compiler/utils/Fingerprint.hsc
parent9e4f633cd8a46cd0c672c09e1823175846652e95 (diff)
downloadhaskell-07ee15915d5a0d6d1aeee137541eec6e9c153e65.tar.gz
omit the local MD5 implementation if we can get it from
GHC.Fingerprint in base instead.
Diffstat (limited to 'compiler/utils/Fingerprint.hsc')
-rw-r--r--compiler/utils/Fingerprint.hsc39
1 files changed, 24 insertions, 15 deletions
diff --git a/compiler/utils/Fingerprint.hsc b/compiler/utils/Fingerprint.hsc
index 20b3ee9da4..8c487f665e 100644
--- a/compiler/utils/Fingerprint.hsc
+++ b/compiler/utils/Fingerprint.hsc
@@ -19,11 +19,18 @@ module Fingerprint (
import Outputable
-import Foreign
-import Foreign.C
import Text.Printf
import Numeric ( readHex )
+##if __GLASGOW_HASKELL__ >= 701
+-- The MD5 implementation is now in base, to support Typeable
+import GHC.Fingerprint
+##endif
+
+##if __GLASGOW_HASKELL__ < 701
+import Foreign
+import Foreign.C
+
-- Using 128-bit MD5 fingerprints for now.
data Fingerprint = Fingerprint {-# UNPACK #-} !Word64 {-# UNPACK #-} !Word64
@@ -33,19 +40,6 @@ data Fingerprint = Fingerprint {-# UNPACK #-} !Word64 {-# UNPACK #-} !Word64
fingerprint0 :: Fingerprint
fingerprint0 = Fingerprint 0 0
-instance Outputable Fingerprint where
- ppr (Fingerprint w1 w2) = text (printf "%016x%016x" i1 i2)
- where i1 = fromIntegral w1 :: Integer
- i2 = fromIntegral w2 :: Integer
- -- printf in GHC 6.4.2 didn't have Word64 instances
-
--- useful for parsing the output of 'md5sum', should we want to do that.
-readHexFingerprint :: String -> Fingerprint
-readHexFingerprint s = Fingerprint w1 w2
- where (s1,s2) = splitAt 16 s
- [(w1,"")] = readHex s1
- [(w2,"")] = readHex (take 16 s2)
-
peekFingerprint :: Ptr Word8 -> IO Fingerprint
peekFingerprint p = do
let peekW64 :: Ptr Word8 -> Int -> Word64 -> IO Word64
@@ -77,3 +71,18 @@ foreign import ccall unsafe "MD5Update"
c_MD5Update :: Ptr MD5Context -> Ptr Word8 -> CInt -> IO ()
foreign import ccall unsafe "MD5Final"
c_MD5Final :: Ptr Word8 -> Ptr MD5Context -> IO ()
+##endif
+
+instance Outputable Fingerprint where
+ ppr (Fingerprint w1 w2) = text (printf "%016x%016x" i1 i2)
+ where i1 = fromIntegral w1 :: Integer
+ i2 = fromIntegral w2 :: Integer
+ -- printf in GHC 6.4.2 didn't have Word64 instances
+
+-- useful for parsing the output of 'md5sum', should we want to do that.
+readHexFingerprint :: String -> Fingerprint
+readHexFingerprint s = Fingerprint w1 w2
+ where (s1,s2) = splitAt 16 s
+ [(w1,"")] = readHex s1
+ [(w2,"")] = readHex (take 16 s2)
+