Produce new-style Cmm from the Cmm parser
[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 import Control.Monad
23
24 mkTickBox :: DynFlags -> Module -> Int -> CmmAGraph
25 mkTickBox dflags mod n
26 = mkStore tick_box (CmmMachOp (MO_Add W64)
27 [ CmmLoad tick_box b64
28 , CmmLit (CmmInt 1 W64)
29 ])
30 where
31 tick_box = cmmIndex dflags W64
32 (CmmLit $ CmmLabel $ mkHpcTicksLabel $ mod)
33 n
34
35 initHpc :: Module -> HpcInfo -> FCode ()
36 -- Emit top-level tables for HPC and return code to initialise
37 initHpc _ (NoHpcInfo {})
38 = return ()
39 initHpc this_mod (HpcInfo tickCount _hashNo)
40 = do dflags <- getDynFlags
41 when (dopt Opt_Hpc dflags) $
42 do emitDataLits (mkHpcTicksLabel this_mod)
43 [ (CmmInt 0 W64)
44 | _ <- take tickCount [0 :: Int ..]
45 ]
46