1 -----------------------------------------------------------------------------
3 -- Code generation for coverage
5 -- (c) Galois Connections, Inc. 2006
7 -----------------------------------------------------------------------------
9 module CgHpc (cgTickBox, initHpc, hpcTable) where
27 cgTickBox :: Module -> Int -> Code
29 let tick_box = (cmmIndex W64
30 (CmmLit $ CmmLabel $ mkHpcTicksLabel $ mod)
33 stmtsC [ CmmStore tick_box
34 (CmmMachOp (MO_Add W64)
35 [ CmmLoad tick_box b64
36 , CmmLit (CmmInt 1 W64)
40 hpcTable :: Module -> HpcInfo -> Code
41 hpcTable this_mod (HpcInfo hpc_tickCount _) = do
43 [ CmmDataLabel mkHpcModuleNameLabel
44 , CmmString $ map (fromIntegral . ord)
48 emitData Data $ [ CmmDataLabel (mkHpcTicksLabel this_mod)
50 [ CmmStaticLit (CmmInt 0 W64)
51 | _ <- take hpc_tickCount [0::Int ..]
54 module_name_str = moduleNameString (Module.moduleName this_mod)
55 full_name_str = if modulePackageId this_mod == mainPackageId
57 else packageIdString (modulePackageId this_mod) ++ "/" ++
60 hpcTable _ (NoHpcInfo {}) = error "TODO: impossible"
62 initHpc :: Module -> HpcInfo -> Code
63 initHpc this_mod (HpcInfo tickCount hashNo)
64 = do { id <- newTemp bWord
69 (CmmLit $ CmmLabel $ mkForeignLabel mod_alloc Nothing False)
72 [ CmmHinted (mkLblExpr mkHpcModuleNameLabel) AddrHint
73 , CmmHinted (word32 tickCount) NoHint
74 , CmmHinted (word32 hashNo) NoHint
75 , CmmHinted (CmmLit $ CmmLabel $ mkHpcTicksLabel $ this_mod) AddrHint
78 NoC_SRT -- No SRT b/c we PlayRisky
82 word32 i = CmmLit (CmmInt (fromIntegral (fromIntegral i :: Word32)) W32)
83 mod_alloc = mkFastString "hs_hpc_module"
84 initHpc _ (NoHpcInfo {}) = panic "initHpc: NoHpcInfo"