Refactor SrcLoc and SrcSpan
[ghc-hetmet.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 CmmDecl
15 import CmmExpr
16 import CLabel
17 import Module
18 import CmmUtils
19 import HscTypes
20 import StaticFlags
21
22 mkTickBox :: Module -> Int -> CmmAGraph
23 mkTickBox 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 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   = whenC opt_Hpc $
39     do  { emitData Data $ [ CmmDataLabel (mkHpcTicksLabel this_mod)
40               ] ++
41               [ CmmStaticLit (CmmInt 0 W64)
42               | _ <- take tickCount [0::Int ..]
43               ]
44        }