1 -----------------------------------------------------------------------------
3 -- Code generation for coverage
5 -- (c) Galois Connections, Inc. 2006
7 -----------------------------------------------------------------------------
9 module CgHpc (cgTickBox, initHpc, hpcTable) where
30 cgTickBox :: Module -> Int -> Code
32 let tick_box = (cmmIndex W64
33 (CmmLit $ CmmLabel $ mkHpcTicksLabel $ mod)
36 stmtsC [ CmmStore tick_box
37 (CmmMachOp (MO_Add W64)
38 [ CmmLoad tick_box b64
39 , CmmLit (CmmInt 1 W64)
43 hpcTable :: Module -> HpcInfo -> Code
44 hpcTable this_mod (HpcInfo hpc_tickCount _) = do
46 [ CmmDataLabel mkHpcModuleNameLabel
47 , CmmString $ map (fromIntegral . ord)
51 emitData Data $ [ CmmDataLabel (mkHpcTicksLabel this_mod)
53 [ CmmStaticLit (CmmInt 0 W64)
54 | _ <- take hpc_tickCount [0::Int ..]
57 module_name_str = moduleNameString (Module.moduleName this_mod)
58 full_name_str = if modulePackageId this_mod == mainPackageId
60 else packageIdString (modulePackageId this_mod) ++ "/" ++
63 hpcTable _ (NoHpcInfo {}) = error "TODO: impossible"
65 initHpc :: Module -> HpcInfo -> Code
66 initHpc this_mod (HpcInfo tickCount hashNo)
67 = do { id <- newTemp bWord
72 (CmmLit $ CmmLabel $ mkForeignLabel mod_alloc Nothing False IsFunction)
75 [ CmmHinted (mkLblExpr mkHpcModuleNameLabel) AddrHint
76 , CmmHinted (word32 tickCount) NoHint
77 , CmmHinted (word32 hashNo) NoHint
78 , CmmHinted (CmmLit $ CmmLabel $ mkHpcTicksLabel $ this_mod) AddrHint
81 NoC_SRT -- No SRT b/c we PlayRisky
85 word32 i = CmmLit (CmmInt (fromIntegral (fromIntegral i :: Word32)) W32)
86 mod_alloc = mkFastString "hs_hpc_module"
87 initHpc _ (NoHpcInfo {}) = panic "initHpc: NoHpcInfo"