2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
4 \section[Desugar]{@deSugar@: the main function}
7 #include "HsVersions.h"
9 module Desugar ( deSugar, pprDsWarnings
10 #if __GLASGOW_HASKELL__ < 200
12 , DsWarnFlavour -- fluff needed for closure,
13 -- removed when compiling with 1.4
19 import CmdLineOpts ( opt_D_dump_ds )
20 import HsSyn ( HsBinds, HsExpr, MonoBinds,
21 SYN_IE(RecFlag), nonRecursive, recursive
23 import TcHsSyn ( SYN_IE(TypecheckedMonoBinds), SYN_IE(TypecheckedHsExpr)
26 import PprCore ( pprCoreBindings )
27 import Name ( isExported )
29 import DsBinds ( dsMonoBinds )
32 import Bag ( unionBags, isEmptyBag )
33 import BasicTypes ( SYN_IE(Module) )
34 import CmdLineOpts ( opt_DoCoreLinting, opt_SccGroup, opt_SccProfilingOn )
35 import CostCentre ( IsCafCC(..), mkAutoCC )
36 import CoreLift ( liftCoreBindings )
37 import CoreLint ( lintCoreBindings )
38 import Id ( nullIdEnv, mkIdEnv, idType,
39 SYN_IE(DictVar), GenId, SYN_IE(Id) )
40 import ErrUtils ( dumpIfSet, doIfSet )
41 import Outputable ( PprStyle(..), pprDumpStyle, pprErrorsStyle, printErrs )
43 import UniqSupply ( splitUniqSupply, UniqSupply )
46 The only trick here is to get the @DsMonad@ stuff off to a good
50 deSugar :: UniqSupply -- name supply
51 -> Module -- module name
52 -> TypecheckedMonoBinds
53 -> IO [CoreBinding] -- output
55 deSugar us mod_name all_binds
57 (us1, us2) = splitUniqSupply us
59 module_and_group = (mod_name, grp_name)
60 grp_name = case opt_SccGroup of
62 Nothing -> mod_name -- default: module name
64 (core_prs, ds_warns) = initDs us1 nullIdEnv module_and_group
65 (dsMonoBinds opt_SccProfilingOn recursive all_binds [])
67 ds_binds = liftCoreBindings us2 [Rec core_prs]
70 -- Display any warnings
71 doIfSet (not (isEmptyBag ds_warns))
72 (printErrs (pprDsWarnings pprErrorsStyle ds_warns)) >>
74 -- Lint result if necessary
75 lintCoreBindings "Desugarer" False ds_binds >>
78 dumpIfSet opt_D_dump_ds "Desugared:"
79 (pprCoreBindings pprDumpStyle ds_binds) >>