{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 704
{-# LANGUAGE Safe #-}
#elif __GLASGOW_HASKELL__ >= 702
{-# LANGUAGE Trustworthy #-}
#endif
module Trace.Hpc.Tix(Tix(..), TixModule(..),
tixModuleName, tixModuleHash, tixModuleTixs,
readTix, writeTix, getTixFileName) where
import System.FilePath (replaceExtension)
import Trace.Hpc.Util (Hash, catchIO, readFileUtf8, writeFileUtf8)
data Tix = Tix [TixModule]
deriving (ReadPrec [Tix]
ReadPrec Tix
Int -> ReadS Tix
ReadS [Tix]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Tix]
$creadListPrec :: ReadPrec [Tix]
readPrec :: ReadPrec Tix
$creadPrec :: ReadPrec Tix
readList :: ReadS [Tix]
$creadList :: ReadS [Tix]
readsPrec :: Int -> ReadS Tix
$creadsPrec :: Int -> ReadS Tix
Read, Int -> Tix -> ShowS
[Tix] -> ShowS
Tix -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Tix] -> ShowS
$cshowList :: [Tix] -> ShowS
show :: Tix -> String
$cshow :: Tix -> String
showsPrec :: Int -> Tix -> ShowS
$cshowsPrec :: Int -> Tix -> ShowS
Show, Tix -> Tix -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Tix -> Tix -> Bool
$c/= :: Tix -> Tix -> Bool
== :: Tix -> Tix -> Bool
$c== :: Tix -> Tix -> Bool
Eq)
data TixModule = TixModule
String
Hash
Int
[Integer]
deriving (ReadPrec [TixModule]
ReadPrec TixModule
Int -> ReadS TixModule
ReadS [TixModule]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TixModule]
$creadListPrec :: ReadPrec [TixModule]
readPrec :: ReadPrec TixModule
$creadPrec :: ReadPrec TixModule
readList :: ReadS [TixModule]
$creadList :: ReadS [TixModule]
readsPrec :: Int -> ReadS TixModule
$creadsPrec :: Int -> ReadS TixModule
Read, Int -> TixModule -> ShowS
[TixModule] -> ShowS
TixModule -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TixModule] -> ShowS
$cshowList :: [TixModule] -> ShowS
show :: TixModule -> String
$cshow :: TixModule -> String
showsPrec :: Int -> TixModule -> ShowS
$cshowsPrec :: Int -> TixModule -> ShowS
Show, TixModule -> TixModule -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TixModule -> TixModule -> Bool
$c/= :: TixModule -> TixModule -> Bool
== :: TixModule -> TixModule -> Bool
$c== :: TixModule -> TixModule -> Bool
Eq)
tixModuleName :: TixModule -> String
tixModuleName :: TixModule -> String
tixModuleName (TixModule String
nm Hash
_ Int
_ [Integer]
_) = String
nm
tixModuleHash :: TixModule -> Hash
tixModuleHash :: TixModule -> Hash
tixModuleHash (TixModule String
_ Hash
h Int
_ [Integer]
_) = Hash
h
tixModuleTixs :: TixModule -> [Integer]
tixModuleTixs :: TixModule -> [Integer]
tixModuleTixs (TixModule String
_ Hash
_ Int
_ [Integer]
tixs) = [Integer]
tixs
readTix :: String
-> IO (Maybe Tix)
readTix :: String -> IO (Maybe Tix)
readTix String
tixFilename =
forall a. IO a -> (IOException -> IO a) -> IO a
catchIO (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Read a => String -> a
read) forall a b. (a -> b) -> a -> b
$ String -> IO String
readFileUtf8 String
tixFilename)
(forall a b. a -> b -> a
const forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing)
writeTix :: String
-> Tix
-> IO ()
writeTix :: String -> Tix -> IO ()
writeTix String
name Tix
tix = String -> String -> IO ()
writeFileUtf8 String
name (forall a. Show a => a -> String
show Tix
tix)
getTixFileName :: String -> String
getTixFileName :: ShowS
getTixFileName String
str = String -> ShowS
replaceExtension String
str String
"tix"