3 % (c) University of Glasgow, 2007
5 \section[Coverage]{@coverage@: the main function}
8 module Coverage (addCoverageTicksToBinds) where
10 #include "HsVersions.h"
30 import System.Time (ClockTime(..))
31 import System.Directory (getModificationTime)
32 import System.IO (FilePath)
33 #if __GLASGOW_HASKELL__ < 603
34 import Compat.Directory ( createDirectoryIfMissing )
36 import System.Directory ( createDirectoryIfMissing )
40 import Data.HashTable ( hashString )
44 %************************************************************************
46 %* The main function: addCoverageTicksToBinds
48 %************************************************************************
51 addCoverageTicksToBinds
54 -> ModLocation -- of the current module
56 -> IO (LHsBinds Id, HpcInfo, ModBreaks)
58 addCoverageTicksToBinds dflags mod mod_loc binds = do
60 case ml_hs_file mod_loc of
62 Nothing -> panic "can not find the original file during hpc trans"
64 if "boot" `isSuffixOf` orig_file then return (binds, noHpcInfo, emptyModBreaks) else do
66 let mod_name = moduleNameString (moduleName mod)
69 = unTM (addTickLHsBinds binds)
73 , inScope = emptyVarSet
80 let entries = reverse $ mixEntries st
82 -- write the mix entries for this module
83 hashNo <- if opt_Hpc then do
84 let hpc_dir = hpcDir dflags
85 let tabStop = 1 -- <tab> counts as a normal char in GHC's location ranges.
86 createDirectoryIfMissing True hpc_dir
87 modTime <- getModificationTime' orig_file
88 let entries' = [ (hpcPos, box)
89 | (span,_,box) <- entries, hpcPos <- [mkHpcPos span] ]
90 when (length entries' /= tickBoxCount st) $ do
91 panic "the number of .mix entries are inconsistent"
92 let hashNo = mixHash orig_file modTime tabStop entries'
93 mixCreate hpc_dir mod_name (Mix orig_file modTime hashNo tabStop entries')
98 -- Todo: use proper src span type
99 breakArray <- newBreakArray $ length entries
101 let locsTicks = listArray (0,tickBoxCount st-1)
102 [ span | (span,_,_) <- entries ]
103 varsTicks = listArray (0,tickBoxCount st-1)
104 [ vars | (_,vars,_) <- entries ]
105 modBreaks = emptyModBreaks
106 { modBreaks_flags = breakArray
107 , modBreaks_locs = locsTicks
108 , modBreaks_vars = varsTicks
111 doIfSet_dyn dflags Opt_D_dump_hpc $ do
112 printDump (pprLHsBinds binds1)
114 return (binds1, HpcInfo (tickBoxCount st) hashNo, modBreaks)
119 liftL :: (Monad m) => (a -> m a) -> Located a -> m (Located a)
120 liftL f (L loc a) = do
124 addTickLHsBinds :: LHsBinds Id -> TM (LHsBinds Id)
125 addTickLHsBinds binds = mapBagM addTickLHsBind binds
127 addTickLHsBind :: LHsBind Id -> TM (LHsBind Id)
128 addTickLHsBind (L pos (AbsBinds abs_tvs abs_dicts abs_exports abs_binds)) = do
129 abs_binds' <- addTickLHsBinds abs_binds
130 return $ L pos $ AbsBinds abs_tvs abs_dicts abs_exports abs_binds'
132 addTickLHsBind (L pos (funBind@(FunBind { fun_id = (L _ id) }))) = do
133 let name = getOccString id
134 decl_path <- getPathEntry
136 (fvs, mg@(MatchGroup matches' ty)) <-
139 addTickMatchGroup (fun_matches funBind)
141 -- Todo: we don't want redundant ticks on simple pattern bindings
142 if not opt_Hpc && isSimplePatBind funBind
144 return $ L pos $ funBind { fun_matches = MatchGroup matches' ty
148 tick_no <- allocATickBox (if null decl_path
149 then TopLevelBox [name]
150 else LocalBox (decl_path ++ [name]))
153 return $ L pos $ funBind { fun_matches = MatchGroup matches' ty
157 -- a binding is a simple pattern binding if it is a funbind with zero patterns
158 isSimplePatBind :: HsBind a -> Bool
159 isSimplePatBind funBind = matchGroupArity (fun_matches funBind) == 0
161 -- TODO: Revisit this
162 addTickLHsBind (L pos (pat@(PatBind { pat_rhs = rhs }))) = do
164 rhs' <- addPathEntry name $ addTickGRHSs False rhs
166 decl_path <- getPathEntry
167 tick_me <- allocTickBox (if null decl_path
168 then TopLevelBox [name]
169 else LocalBox (name : decl_path))
171 return $ L pos $ pat { pat_rhs = rhs' }
173 {- only internal stuff, not from source, uses VarBind, so we ignore it.
174 addTickLHsBind (VarBind var_id var_rhs) = do
175 var_rhs' <- addTickLHsExpr var_rhs
176 return $ VarBind var_id var_rhs'
178 addTickLHsBind other = return other
180 -- add a tick to the expression no matter what it is
181 addTickLHsExprAlways :: LHsExpr Id -> TM (LHsExpr Id)
182 addTickLHsExprAlways (L pos e0) = do
183 allocTickBox (ExpBox False) pos $ addTickHsExpr e0
185 addTickLHsExprNeverOrAlways :: LHsExpr Id -> TM (LHsExpr Id)
186 addTickLHsExprNeverOrAlways e
187 | opt_Hpc = addTickLHsExprNever e
188 | otherwise = addTickLHsExprAlways e
190 addTickLHsExprNeverOrMaybe :: LHsExpr Id -> TM (LHsExpr Id)
191 addTickLHsExprNeverOrMaybe e
192 | opt_Hpc = addTickLHsExprNever e
193 | otherwise = addTickLHsExpr e
195 -- version of addTick that does not actually add a tick,
196 -- because the scope of this tick is completely subsumed by
198 addTickLHsExprNever :: LHsExpr Id -> TM (LHsExpr Id)
199 addTickLHsExprNever (L pos e0) = do
200 e1 <- addTickHsExpr e0
203 -- selectively add ticks to interesting expressions
204 addTickLHsExpr :: LHsExpr Id -> TM (LHsExpr Id)
205 addTickLHsExpr (L pos e0) = do
206 if opt_Hpc || isGoodBreakExpr e0
208 allocTickBox (ExpBox False) pos $ addTickHsExpr e0
210 e1 <- addTickHsExpr e0
213 -- general heuristic: expressions which do not denote values are good break points
214 isGoodBreakExpr :: HsExpr Id -> Bool
215 isGoodBreakExpr (HsApp {}) = True
216 isGoodBreakExpr (OpApp {}) = True
217 isGoodBreakExpr (NegApp {}) = True
218 isGoodBreakExpr (HsCase {}) = True
219 isGoodBreakExpr (HsIf {}) = True
220 isGoodBreakExpr (RecordCon {}) = True
221 isGoodBreakExpr (RecordUpd {}) = True
222 isGoodBreakExpr (ArithSeq {}) = True
223 isGoodBreakExpr (PArrSeq {}) = True
224 isGoodBreakExpr other = False
226 addTickLHsExprOptAlt :: Bool -> LHsExpr Id -> TM (LHsExpr Id)
227 addTickLHsExprOptAlt oneOfMany (L pos e0)
228 | not opt_Hpc = addTickLHsExpr (L pos e0)
230 allocTickBox (ExpBox oneOfMany) pos $
233 addBinTickLHsExpr :: (Bool -> BoxLabel) -> LHsExpr Id -> TM (LHsExpr Id)
234 addBinTickLHsExpr boxLabel (L pos e0) = do
235 e1 <- addTickHsExpr e0
236 allocBinTickBox boxLabel $ L pos e1
238 addTickHsExpr :: HsExpr Id -> TM (HsExpr Id)
239 addTickHsExpr e@(HsVar id) = do freeVar id; return e
240 addTickHsExpr e@(HsIPVar _) = return e
241 addTickHsExpr e@(HsOverLit _) = return e
242 addTickHsExpr e@(HsLit _) = return e
243 addTickHsExpr e@(HsLam matchgroup) =
244 liftM HsLam (addTickMatchGroup matchgroup)
245 addTickHsExpr (HsApp e1 e2) =
246 liftM2 HsApp (addTickLHsExprNever e1) (addTickLHsExpr e2)
247 addTickHsExpr (OpApp e1 e2 fix e3) =
250 (addTickLHsExprNever e2)
253 addTickHsExpr (NegApp e neg) =
256 (addTickSyntaxExpr hpcSrcSpan neg)
257 addTickHsExpr (HsPar e) = liftM HsPar (addTickLHsExprNeverOrMaybe e)
258 addTickHsExpr (SectionL e1 e2) =
262 addTickHsExpr (SectionR e1 e2) =
266 addTickHsExpr (HsCase e mgs) =
269 (addTickMatchGroup mgs)
270 addTickHsExpr (HsIf e1 e2 e3) =
272 (addBinTickLHsExpr (BinBox CondBinBox) e1)
273 (addTickLHsExprOptAlt True e2)
274 (addTickLHsExprOptAlt True e3)
275 addTickHsExpr (HsLet binds e) =
277 (addTickHsLocalBinds binds) -- to think about: !patterns.
278 (bindLocals (map unLoc $ collectLocalBinders binds) $
279 addTickLHsExprNeverOrAlways e)
280 addTickHsExpr (HsDo cxt stmts last_exp srcloc) = do
281 (stmts', last_exp') <- addTickLStmts' forQual stmts
282 (addTickLHsExpr last_exp)
283 return (HsDo cxt stmts' last_exp' srcloc)
285 forQual = case cxt of
286 ListComp -> Just $ BinBox QualBinBox
288 addTickHsExpr (ExplicitList ty es) =
291 (mapM (addTickLHsExpr) es)
292 addTickHsExpr (ExplicitPArr {}) = error "addTickHsExpr: ExplicitPArr"
293 addTickHsExpr (ExplicitTuple es box) =
295 (mapM (addTickLHsExpr) es)
297 addTickHsExpr (RecordCon id ty rec_binds) =
301 (addTickHsRecordBinds rec_binds)
302 addTickHsExpr (RecordUpd e rec_binds cons tys1 tys2) =
305 (addTickHsRecordBinds rec_binds)
306 (return cons) (return tys1) (return tys2)
308 addTickHsExpr (ExprWithTySig {}) = error "addTickHsExpr: ExprWithTySig"
309 addTickHsExpr (ExprWithTySigOut e ty) =
310 liftM2 ExprWithTySigOut
311 (addTickLHsExprNever e) -- No need to tick the inner expression
312 -- for expressions with signatures
314 addTickHsExpr (ArithSeq ty arith_seq) =
317 (addTickArithSeqInfo arith_seq)
318 addTickHsExpr (HsTickPragma (file,(l1,c1),(l2,c2)) (L pos e0)) = do
319 e2 <- allocTickBox (ExpBox False) pos $
322 addTickHsExpr (PArrSeq {}) = error "addTickHsExpr: PArrSeq"
323 addTickHsExpr (HsSCC {}) = error "addTickHsExpr: HsSCC"
324 addTickHsExpr (HsCoreAnn {}) = error "addTickHsExpr: HsCoreAnn"
325 addTickHsExpr e@(HsBracket {}) = return e
326 addTickHsExpr e@(HsBracketOut {}) = return e
327 addTickHsExpr e@(HsSpliceE {}) = return e
328 addTickHsExpr (HsProc pat cmdtop) =
331 (liftL (addTickHsCmdTop) cmdtop)
332 addTickHsExpr (HsWrap w e) =
335 (addTickHsExpr e) -- explicitly no tick on inside
336 addTickHsExpr (HsArrApp e1 e2 ty1 arr_ty lr) =
343 addTickHsExpr (HsArrForm e fix cmdtop) =
347 (mapM (liftL (addTickHsCmdTop)) cmdtop)
349 addTickHsExpr e@(HsType ty) = return e
351 -- Should never happen in expression content.
352 addTickHsExpr (EAsPat _ _) = error "addTickHsExpr: EAsPat _ _"
353 addTickHsExpr (ELazyPat _) = error "addTickHsExpr: ELazyPat _"
354 addTickHsExpr (EWildPat) = error "addTickHsExpr: EWildPat"
355 addTickHsExpr (HsBinTick _ _ _) = error "addTickhsExpr: HsBinTick _ _ _"
356 addTickHsExpr (HsTick _ _ _) = error "addTickhsExpr: HsTick _ _"
358 addTickMatchGroup (MatchGroup matches ty) = do
359 let isOneOfMany = matchesOneOfMany matches
360 matches' <- mapM (liftL (addTickMatch isOneOfMany)) matches
361 return $ MatchGroup matches' ty
363 addTickMatch :: Bool -> Match Id -> TM (Match Id)
364 addTickMatch isOneOfMany (Match pats opSig gRHSs) =
365 bindLocals (collectPatsBinders pats) $ do
366 gRHSs' <- addTickGRHSs isOneOfMany gRHSs
367 return $ Match pats opSig gRHSs'
369 addTickGRHSs :: Bool -> GRHSs Id -> TM (GRHSs Id)
370 addTickGRHSs isOneOfMany (GRHSs guarded local_binds) = do
371 bindLocals binders $ do
372 local_binds' <- addTickHsLocalBinds local_binds
373 guarded' <- mapM (liftL (addTickGRHS isOneOfMany)) guarded
374 return $ GRHSs guarded' local_binds'
376 binders = map unLoc (collectLocalBinders local_binds)
378 addTickGRHS :: Bool -> GRHS Id -> TM (GRHS Id)
379 addTickGRHS isOneOfMany (GRHS stmts expr) = do
380 (stmts',expr') <- addTickLStmts' (Just $ BinBox $ GuardBinBox) stmts
381 (if opt_Hpc then addTickLHsExprOptAlt isOneOfMany expr
382 else addTickLHsExprAlways expr)
383 return $ GRHS stmts' expr'
385 addTickLStmts :: (Maybe (Bool -> BoxLabel)) -> [LStmt Id] -> TM [LStmt Id]
386 addTickLStmts isGuard stmts = do
387 (stmts, _) <- addTickLStmts' isGuard stmts (return ())
390 addTickLStmts' :: (Maybe (Bool -> BoxLabel)) -> [LStmt Id] -> TM a
391 -> TM ([LStmt Id], a)
392 addTickLStmts' isGuard lstmts res
393 = bindLocals binders $ do
394 lstmts' <- mapM (liftL (addTickStmt isGuard)) lstmts
398 binders = map unLoc (collectLStmtsBinders lstmts)
400 addTickStmt :: (Maybe (Bool -> BoxLabel)) -> Stmt Id -> TM (Stmt Id)
401 addTickStmt isGuard (BindStmt pat e bind fail) = do
404 (addTickLHsExprAlways e)
405 (addTickSyntaxExpr hpcSrcSpan bind)
406 (addTickSyntaxExpr hpcSrcSpan fail)
407 addTickStmt isGuard (ExprStmt e bind' ty) = do
410 (addTickSyntaxExpr hpcSrcSpan bind')
413 addTick e | Just fn <- isGuard = addBinTickLHsExpr fn e
414 | otherwise = addTickLHsExprAlways e
416 addTickStmt isGuard (LetStmt binds) = do
418 (addTickHsLocalBinds binds)
419 addTickStmt isGuard (ParStmt pairs) = do
420 liftM ParStmt (mapM process pairs)
422 process (stmts,ids) =
424 (addTickLStmts isGuard stmts)
426 addTickStmt isGuard (RecStmt stmts ids1 ids2 tys dictbinds) = do
428 (addTickLStmts isGuard stmts)
432 (addTickDictBinds dictbinds)
434 addTickHsLocalBinds :: HsLocalBinds Id -> TM (HsLocalBinds Id)
435 addTickHsLocalBinds (HsValBinds binds) =
437 (addTickHsValBinds binds)
438 addTickHsLocalBinds (HsIPBinds binds) =
440 (addTickHsIPBinds binds)
441 addTickHsLocalBinds (EmptyLocalBinds) = return EmptyLocalBinds
443 addTickHsValBinds (ValBindsOut binds sigs) =
445 (mapM (\ (rec,binds') ->
448 (addTickLHsBinds binds'))
452 addTickHsIPBinds (IPBinds ipbinds dictbinds) =
454 (mapM (liftL (addTickIPBind)) ipbinds)
455 (addTickDictBinds dictbinds)
457 addTickIPBind :: IPBind Id -> TM (IPBind Id)
458 addTickIPBind (IPBind nm e) =
463 -- There is no location here, so we might need to use a context location??
464 addTickSyntaxExpr :: SrcSpan -> SyntaxExpr Id -> TM (SyntaxExpr Id)
465 addTickSyntaxExpr pos x = do
466 L _ x' <- addTickLHsExpr (L pos x)
468 -- we do not walk into patterns.
469 addTickLPat :: LPat Id -> TM (LPat Id)
470 addTickLPat pat = return pat
472 addTickHsCmdTop :: HsCmdTop Id -> TM (HsCmdTop Id)
473 addTickHsCmdTop (HsCmdTop cmd tys ty syntaxtable) =
480 addTickLHsCmd :: LHsCmd Id -> TM (LHsCmd Id)
481 addTickLHsCmd x = addTickLHsExpr x
483 addTickDictBinds :: DictBinds Id -> TM (DictBinds Id)
484 addTickDictBinds x = addTickLHsBinds x
486 addTickHsRecordBinds :: HsRecordBinds Id -> TM (HsRecordBinds Id)
487 addTickHsRecordBinds (HsRecordBinds pairs) = liftM HsRecordBinds (mapM process pairs)
492 (addTickLHsExpr expr)
494 addTickArithSeqInfo :: ArithSeqInfo Id -> TM (ArithSeqInfo Id)
495 addTickArithSeqInfo (From e1) =
498 addTickArithSeqInfo (FromThen e1 e2) =
502 addTickArithSeqInfo (FromTo e1 e2) =
506 addTickArithSeqInfo (FromThenTo e1 e2 e3) =
514 data TickTransState = TT { tickBoxCount:: Int
515 , mixEntries :: [MixEntry]
518 data TickTransEnv = TTE { modName :: String
519 , declPath :: [String]
525 type FreeVars = OccEnv Id
529 -- For breakpoints we want to collect the free variables of an
530 -- expression for pinning on the HsTick. We don't want to collect
531 -- *all* free variables though: in particular there's no point pinning
532 -- on free variables that are will otherwise be in scope at the GHCi
533 -- prompt, which means all top-level bindings. Unfortunately detecting
534 -- top-level bindings isn't easy (collectHsBindsBinders on the top-level
535 -- bindings doesn't do it), so we keep track of a set of "in-scope"
536 -- variables in addition to the free variables, and the former is used
537 -- to filter additions to the latter. This gives us complete control
538 -- over what free variables we track.
540 data TM a = TM { unTM :: TickTransEnv -> TickTransState -> (a,FreeVars,TickTransState) }
541 -- a combination of a state monad (TickTransState) and a writer
544 instance Monad TM where
545 return a = TM $ \ env st -> (a,noFVs,st)
546 (TM m) >>= k = TM $ \ env st ->
549 case unTM (k r1) env st1 of
551 (r2, fv1 `plusOccEnv` fv2, st2)
553 -- getState :: TM TickTransState
554 -- getState = TM $ \ env st -> (st, noFVs, st)
556 setState :: (TickTransState -> TickTransState) -> TM ()
557 setState f = TM $ \ env st -> ((), noFVs, f st)
559 getEnv :: TM TickTransEnv
560 getEnv = TM $ \ env st -> (env, noFVs, st)
562 withEnv :: (TickTransEnv -> TickTransEnv) -> TM a -> TM a
563 withEnv f (TM m) = TM $ \ env st ->
565 (a, fvs, st') -> (a, fvs, st')
567 getFreeVars :: TM a -> TM (FreeVars, a)
569 = TM $ \ env st -> case m env st of (a, fv, st') -> ((fv,a), fv, st')
571 freeVar :: Id -> TM ()
572 freeVar id = TM $ \ env st ->
573 if id `elemVarSet` inScope env
574 then ((), unitOccEnv (nameOccName (idName id)) id, st)
577 addPathEntry :: String -> TM a -> TM a
578 addPathEntry nm = withEnv (\ env -> env { declPath = declPath env ++ [nm] })
580 getPathEntry :: TM [String]
581 getPathEntry = declPath `liftM` getEnv
583 bindLocals :: [Id] -> TM a -> TM a
584 bindLocals new_ids (TM m)
586 case m env{ inScope = inScope env `extendVarSetList` new_ids } st of
587 (r, fv, st') -> (r, fv `delListFromUFM` occs, st')
588 where occs = [ nameOccName (idName id) | id <- new_ids ]
590 -- the tick application inherits the source position of its
591 -- expression argument to support nested box allocations
592 allocTickBox :: BoxLabel -> SrcSpan -> TM (HsExpr Id) -> TM (LHsExpr Id)
593 allocTickBox boxLabel pos m | isGoodSrcSpan' pos = do
594 (fvs, e) <- getFreeVars m
596 let c = tickBoxCount st
599 me = (pos, map (nameOccName.idName) ids, boxLabel)
601 ( L pos (HsTick c ids (L pos e))
603 , st {tickBoxCount=c+1,mixEntries=me:mes}
605 allocTickBox boxLabel pos m = do e <- m; return (L pos e)
607 -- the tick application inherits the source position of its
608 -- expression argument to support nested box allocations
609 allocATickBox :: BoxLabel -> SrcSpan -> FreeVars -> TM (Maybe (Int,[Id]))
610 allocATickBox boxLabel pos fvs | isGoodSrcSpan' pos = TM $ \ env st ->
611 let me = (pos, map (nameOccName.idName) ids, boxLabel)
617 , st {tickBoxCount=c+1, mixEntries=me:mes}
619 allocATickBox boxLabel pos fvs = return Nothing
621 allocBinTickBox :: (Bool -> BoxLabel) -> LHsExpr Id -> TM (LHsExpr Id)
622 allocBinTickBox boxLabel (L pos e) | isGoodSrcSpan' pos = TM $ \ env st ->
623 let meT = (pos,[],boxLabel True)
624 meF = (pos,[],boxLabel False)
625 meE = (pos,[],ExpBox False)
630 then ( L pos $ HsTick c [] $ L pos $ HsBinTick (c+1) (c+2) (L pos e)
631 -- notice that F and T are reversed,
632 -- because we are building the list in
635 , st {tickBoxCount=c+3 , mixEntries=meF:meT:meE:mes}
638 ( L pos $ HsTick c [] $ L pos e
640 , st {tickBoxCount=c+1,mixEntries=meE:mes}
643 allocBinTickBox boxLabel e = return e
646 | not (isGoodSrcSpan pos) = False
647 | start == end = False
650 start = srcSpanStart pos
653 mkHpcPos :: SrcSpan -> HpcPos
655 | not (isGoodSrcSpan' pos) = panic "bad source span; expected such spans to be filtered out"
658 start = srcSpanStart pos
660 hpcPos = toHpcPos ( srcLocLine start
661 , srcLocCol start + 1
666 noHpcPos = toHpcPos (0,0,0,0)
668 hpcSrcSpan = mkGeneralSrcSpan (FSLIT("Haskell Program Coverage internals"))
673 matchesOneOfMany :: [LMatch Id] -> Bool
674 matchesOneOfMany lmatches = sum (map matchCount lmatches) > 1
676 matchCount (L _ (Match _pats _ty (GRHSs grhss _binds))) = length grhss
681 -- | 'Mix' is the information about a modules static properties, like
682 -- location of Tix's in a file.
683 -- tab stops are the size of a tab in the provided line:colunm values.
684 -- * In GHC, this is 1 (a tab is just a character)
685 -- * With hpc-tracer, this is 8 (a tab represents several spaces).
688 FilePath -- ^location of original file
689 Integer -- ^time (in seconds) of original file's last update, since 1970.
690 Int -- ^hash of mix entry + timestamp
691 Int -- ^tab stop value.
692 [MixEntry_] -- ^entries
693 deriving (Show, Read)
695 -- We would rather use ClockTime in Mix, but ClockTime has no Read instance in 6.4 and before,
696 -- but does in 6.6. Definining the instance for ClockTime here is the Wrong Thing to do,
697 -- because if some other program also defined that instance, we will not be able to compile.
699 type MixEntry = (SrcSpan, [OccName], BoxLabel)
700 type MixEntry_ = (HpcPos, BoxLabel)
702 data BoxLabel = ExpBox Bool -- isAlt
703 | TopLevelBox [String]
705 | BinBox CondBox Bool
706 deriving (Read, Show, Eq, Ord)
708 data CondBox = GuardBinBox
711 deriving (Read, Show, Eq, Ord)
713 -- For the hash value, we hash everything: the file name,
714 -- the timestamp of the original source file, the tab stop,
715 -- and the mix entries. We cheat, and hash the show'd string.
716 -- This hash only has to be hashed at Mix creation time,
717 -- and is for sanity checking only.
719 mixHash :: FilePath -> Integer -> Int -> [MixEntry_] -> Int
720 mixHash file tm tabstop entries = fromIntegral $ hashString
721 (show $ Mix file tm 0 tabstop entries)
723 mixCreate :: String -> String -> Mix -> IO ()
724 mixCreate dirName modName mix =
725 writeFile (mixName dirName modName) (show mix)
727 mixName :: FilePath -> String -> String
728 mixName dirName name = dirName ++ "/" ++ name ++ ".mix"
730 getModificationTime' :: FilePath -> IO Integer
731 getModificationTime' file = do
732 (TOD sec _) <- System.Directory.getModificationTime file
735 -- a program index records module names and numbers of tick-boxes
736 -- introduced in each module that has been transformed for coverage
738 data HpcPos = P !Int !Int !Int !Int deriving (Eq)
740 toHpcPos :: (Int,Int,Int,Int) -> HpcPos
741 toHpcPos (l1,c1,l2,c2) = P l1 c1 l2 c2
743 instance Show HpcPos where
744 show (P l1 c1 l2 c2) = show l1 ++ ':' : show c1 ++ '-' : show l2 ++ ':' : show c2
746 instance Read HpcPos where
747 readsPrec _i pos = [(toHpcPos (read l1,read c1,read l2,read c2),after)]
749 (before,after) = span (/= ',') pos
750 (lhs,rhs) = case span (/= '-') before of
751 (lhs,'-':rhs) -> (lhs,rhs)
752 (lhs,"") -> (lhs,lhs)
753 (l1,':':c1) = span (/= ':') lhs
754 (l2,':':c2) = span (/= ':') rhs