[project @ 1998-02-03 17:49:21 by simonm]
[ghc-hetmet.git] / ghc / compiler / deSugar / Desugar.lhs
1 %
2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
3 %
4 \section[Desugar]{@deSugar@: the main function}
5
6 \begin{code}
7 module Desugar ( deSugar, pprDsWarnings ) where
8
9 #include "HsVersions.h"
10
11 import CmdLineOpts      ( opt_D_dump_ds )
12 import HsSyn            ( MonoBinds )
13 import TcHsSyn          ( TypecheckedMonoBinds )
14 import CoreSyn
15 import PprCore          ( pprCoreBindings )
16 import DsMonad
17 import DsBinds          ( dsMonoBinds )
18 import DsUtils
19
20 import Bag              ( isEmptyBag )
21 import BasicTypes       ( Module )
22 import CmdLineOpts      ( opt_SccGroup, opt_SccProfilingOn )
23 import CoreLift         ( liftCoreBindings )
24 import CoreLint         ( lintCoreBindings )
25 import Id               ( nullIdEnv, GenId, Id )
26 import ErrUtils         ( dumpIfSet, doIfSet )
27 import Outputable
28 import UniqSupply       ( splitUniqSupply, UniqSupply )
29 \end{code}
30
31 The only trick here is to get the @DsMonad@ stuff off to a good
32 start.
33
34 \begin{code}
35 deSugar :: UniqSupply           -- name supply
36         -> Module               -- module name
37         -> TypecheckedMonoBinds
38         -> IO [CoreBinding]     -- output
39
40 deSugar us mod_name all_binds
41   = let
42         (us1, us2) = splitUniqSupply us
43
44         module_and_group = (mod_name, grp_name)
45         grp_name  = case opt_SccGroup of
46                         Just xx -> _PK_ xx
47                         Nothing -> mod_name     -- default: module name
48
49         (core_prs, ds_warns) = initDs us1 nullIdEnv module_and_group 
50                                (dsMonoBinds opt_SccProfilingOn all_binds [])
51
52         ds_binds = liftCoreBindings us2 [Rec core_prs]
53     in
54
55         -- Display any warnings
56     doIfSet (not (isEmptyBag ds_warns))
57         (printErrs (pprDsWarnings ds_warns)) >>
58
59         -- Lint result if necessary
60     lintCoreBindings "Desugarer" False ds_binds >>
61
62         -- Dump output
63     dumpIfSet opt_D_dump_ds "Desugared:"
64         (pprCoreBindings ds_binds)      >>
65
66     return ds_binds    
67 \end{code}