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 = sdocWithDynFlags
$ \dflags
->
27 if not (gopt Opt_SccProfilingOn dflags
)
30 [ text
"static void prof_init_" <> ppr this_mod
31 <> text
"(void) __attribute__((constructor));"
32 , text
"static void prof_init_" <> ppr this_mod
<> text
"(void)"
34 map emitRegisterCC local_CCs
++
35 map emitRegisterCCS singleton_CCSs
40 ptext
(sLit
"extern CostCentre ") <> cc_lbl
<> ptext
(sLit
"[];") $$
41 ptext
(sLit
"REGISTER_CC(") <> cc_lbl
<> char
')' <> semi
42 where cc_lbl
= ppr
(mkCCLabel cc
)
44 ptext
(sLit
"extern CostCentreStack ") <> ccs_lbl
<> ptext
(sLit
"[];") $$
45 ptext
(sLit
"REGISTER_CCS(") <> ccs_lbl
<> char
')' <> semi
46 where ccs_lbl
= ppr
(mkCCSLabel ccs
)