1 -----------------------------------------------------------------------------
3 -- Code generation for coverage
5 -- (c) Galois Connections, Inc. 2006
7 -----------------------------------------------------------------------------
9 module CgHpc (cgTickBox, initHpc, hpcTable) where
25 cgTickBox :: Module -> Int -> Code
27 let tick_box = (cmmIndex I64
28 (CmmLit $ CmmLabel $ mkHpcTicksLabel $ mod)
31 stmtsC [ CmmStore tick_box
32 (CmmMachOp (MO_Add I64)
33 [ CmmLoad tick_box I64
34 , CmmLit (CmmInt 1 I64)
37 let ext_tick_box = CmmLit $ CmmLabel $ mkHpcModuleOffsetLabel $ mod
39 whenC (opt_Hpc_Tracer) $ do
44 (CmmLit $ CmmLabel $ mkForeignLabel visible_tick Nothing False)
47 [ (CmmMachOp (MO_Add I32)
48 [ CmmLoad ext_tick_box I32
49 , CmmLit (CmmInt (fromIntegral n) I32)
52 , ( CmmReg (CmmGlobal CurrentTSO)
58 visible_tick = mkFastString "hs_hpc_tick"
60 hpcTable :: Module -> HpcInfo -> Code
61 hpcTable this_mod (HpcInfo hpc_tickCount _) = do
63 [ CmmDataLabel mkHpcModuleNameLabel
64 , CmmString $ map (fromIntegral . ord)
68 emitData Data -- change Offset => Data or Info
69 [ CmmDataLabel (mkHpcModuleOffsetLabel this_mod)
70 , CmmStaticLit (CmmInt 0 I32) -- stored offset?
72 emitData Data $ [ CmmDataLabel (mkHpcTicksLabel this_mod)
74 [ CmmStaticLit (CmmInt 0 I64)
75 | _ <- take hpc_tickCount [0..]
78 module_name_str = moduleNameString (Module.moduleName this_mod)
79 hpcTable this_mod (NoHpcInfo) = error "TODO: impossible"
81 initHpc :: Module -> HpcInfo -> Code
82 initHpc this_mod (HpcInfo tickCount hashNo)
83 = do { id <- newTemp wordRep
88 (CmmLit $ CmmLabel $ mkForeignLabel mod_alloc Nothing False)
91 [ (mkLblExpr mkHpcModuleNameLabel,PtrHint)
92 , (CmmLit $ mkIntCLit tickCount,NoHint)
93 , (CmmLit $ mkIntCLit hashNo,NoHint)
94 , (CmmLit $ CmmLabel $ mkHpcTicksLabel $ this_mod,PtrHint)
97 ; let ext_tick_box = CmmLit $ CmmLabel $ mkHpcModuleOffsetLabel $ this_mod
98 ; stmtsC [ CmmStore ext_tick_box (CmmReg id) ]
101 mod_alloc = mkFastString "hs_hpc_module"