Merge branch 'master' of http://darcs.haskell.org/ghc
[ghc.git] / compiler / codeGen / StgCmmHpc.hs
1 -----------------------------------------------------------------------------
2 --
3 -- Code generation for coverage
4 --
5 -- (c) Galois Connections, Inc. 2006
6 --
7 -----------------------------------------------------------------------------
8
9 module StgCmmHpc ( initHpc, mkTickBox ) where
10
11 import StgCmmMonad
12
13 import MkGraph
14 import CmmExpr
15 import CLabel
16 import Module
17 import CmmUtils
18 import StgCmmUtils
19 import HscTypes
20 import DynFlags
21
22 mkTickBox :: DynFlags -> Module -> Int -> CmmAGraph
23 mkTickBox dflags mod n
24 = mkStore tick_box (CmmMachOp (MO_Add W64)
25 [ CmmLoad tick_box b64
26 , CmmLit (CmmInt 1 W64)
27 ])
28 where
29 tick_box = cmmIndex dflags W64
30 (CmmLit $ CmmLabel $ mkHpcTicksLabel $ mod)
31 n
32
33 initHpc :: Module -> HpcInfo -> FCode ()
34 -- Emit top-level tables for HPC and return code to initialise
35 initHpc _ (NoHpcInfo {})
36 = return ()
37 initHpc this_mod (HpcInfo tickCount _hashNo)
38 = do dflags <- getDynFlags
39 whenC (dopt Opt_Hpc dflags) $
40 do emitDataLits (mkHpcTicksLabel this_mod)
41 [ (CmmInt 0 W64)
42 | _ <- take tickCount [0 :: Int ..]
43 ]
44