`M-x untabify` & `M-x delete-trailing-whitespaces`
[packages/hpc.git] / Trace / Hpc / Tix.hs
1 {-# LANGUAGE CPP #-}
2 #ifdef __GLASGOW_HASKELL__
3 {-# LANGUAGE Safe #-}
4 #endif
5 ------------------------------------------------------------
6 -- Andy Gill and Colin Runciman, June 2006
7 ------------------------------------------------------------
8
9 -- | Datatypes and file-access routines for the tick data file
10 -- used by HPC. (.tix)
11 module Trace.Hpc.Tix(Tix(..), TixModule(..),
12 tixModuleName, tixModuleHash, tixModuleTixs,
13 readTix, writeTix, getTixFileName) where
14
15 import Data.List (isSuffixOf)
16 import Trace.Hpc.Util (Hash, catchIO)
17
18 -- 'Tix ' is the storage format for our dynamic imformation about what
19 -- boxes are ticked.
20 data Tix = Tix [TixModule]
21 deriving (Read, Show, Eq)
22
23 data TixModule = TixModule
24 String -- module name
25 Hash -- hash number
26 Int -- length of tix list (allows pre-allocation at parse time).
27 [Integer] -- actual ticks
28 deriving (Read, Show, Eq)
29
30 tixModuleName :: TixModule -> String
31 tixModuleName (TixModule nm _ _ _) = nm
32 tixModuleHash :: TixModule -> Hash
33 tixModuleHash (TixModule _ h _ _) = h
34 tixModuleTixs :: TixModule -> [Integer]
35 tixModuleTixs (TixModule _ _ _ tixs) = tixs
36
37 -- We /always/ read and write Tix from the current working directory.
38
39 -- read a Tix File.
40 readTix :: String
41 -> IO (Maybe Tix)
42 readTix tix_filename =
43 catchIO (do contents <- readFile $ tix_filename
44 return $ Just $ read contents)
45 (\ _ -> return $ Nothing)
46
47 -- write a Tix File.
48 writeTix :: String
49 -> Tix
50 -> IO ()
51 writeTix name tix =
52 writeFile name (show tix)
53
54 {-
55 tixName :: String -> String
56 tixName name = name ++ ".tix"
57 -}
58
59 -- getTixFullName takes a binary or .tix-file name,
60 -- and normalizes it into a .tix-file name.
61 getTixFileName :: String -> String
62 getTixFileName str | ".tix" `isSuffixOf` str
63 = str
64 | otherwise
65 = str ++ ".tix"