1 -- -----------------------------------------------------------------------------
3 -- (c) The University of Glasgow, 2011
5 -- Generate code to initialise cost centres
7 -- -----------------------------------------------------------------------------
9 module ProfInit (profilingInitCode) where
18 -- -----------------------------------------------------------------------------
19 -- Initialising cost centres
21 -- We must produce declarations for the cost-centres defined in this
24 profilingInitCode :: Module -> CollectedCCs -> SDoc
25 profilingInitCode this_mod (local_CCs, ___extern_CCs, singleton_CCSs)
26 | not opt_SccProfilingOn = empty
29 [ text "static void prof_init_" <> ppr this_mod
30 <> text "(void) __attribute__((constructor));"
31 , text "static void prof_init_" <> ppr this_mod <> text "(void)"
33 map emitRegisterCC local_CCs ++
34 map emitRegisterCCS singleton_CCSs
39 ptext (sLit "extern CostCentre ") <> cc_lbl <> ptext (sLit "[];") $$
40 ptext (sLit "REGISTER_CC(") <> cc_lbl <> char ')' <> semi
41 where cc_lbl = ppr (mkCCLabel cc)
43 ptext (sLit "extern CostCentreStack ") <> ccs_lbl <> ptext (sLit "[];") $$
44 ptext (sLit "REGISTER_CCS(") <> ccs_lbl <> char ')' <> semi
45 where ccs_lbl = ppr (mkCCSLabel ccs)