More CPP removal: pprDynamicLinkerAsmLabel in CLabel
[ghc.git] / compiler / profiling / ProfInit.hs
1 -- -----------------------------------------------------------------------------
2 --
3 -- (c) The University of Glasgow, 2011
4 --
5 -- Generate code to initialise cost centres
6 --
7 -- -----------------------------------------------------------------------------
8
9 module ProfInit (profilingInitCode) where
10
11 import CLabel
12 import CostCentre
13 import Outputable
14 import Platform
15 import StaticFlags
16 import FastString
17 import Module
18
19 -- -----------------------------------------------------------------------------
20 -- Initialising cost centres
21
22 -- We must produce declarations for the cost-centres defined in this
23 -- module;
24
25 profilingInitCode :: Platform -> Module -> CollectedCCs -> SDoc
26 profilingInitCode platform this_mod (local_CCs, ___extern_CCs, singleton_CCSs)
27 | not opt_SccProfilingOn = empty
28 | otherwise
29 = vcat
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)"
33 , braces (vcat (
34 map emitRegisterCC local_CCs ++
35 map emitRegisterCCS singleton_CCSs
36 ))
37 ]
38 where
39 emitRegisterCC cc =
40 ptext (sLit "extern CostCentre ") <> cc_lbl <> ptext (sLit "[];") $$
41 ptext (sLit "REGISTER_CC(") <> cc_lbl <> char ')' <> semi
42 where cc_lbl = pprPlatform platform (mkCCLabel cc)
43 emitRegisterCCS ccs =
44 ptext (sLit "extern CostCentreStack ") <> ccs_lbl <> ptext (sLit "[];") $$
45 ptext (sLit "REGISTER_CCS(") <> ccs_lbl <> char ')' <> semi
46 where ccs_lbl = pprPlatform platform (mkCCSLabel ccs)