[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / compiler / deSugar / Desugar.lhs
index 6e02ef8..2cb65c9 100644 (file)
@@ -1,31 +1,29 @@
 %
-% (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
+% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
 %
 \section[Desugar]{@deSugar@: the main function}
 
 \begin{code}
-module Desugar ( deSugar, pprDsWarnings ) where
+module Desugar ( deSugar ) where
 
 #include "HsVersions.h"
 
 import CmdLineOpts     ( opt_D_dump_ds )
 import HsSyn           ( MonoBinds )
 import TcHsSyn         ( TypecheckedMonoBinds, TypecheckedForeignDecl )
-
 import CoreSyn
-import PprCore         ( pprCoreBindings )
 import DsMonad
 import DsBinds         ( dsMonoBinds )
 import DsForeign       ( dsForeigns )
 import DsUtils
+import DsExpr          ()      -- Forces DsExpr to be compiled; DsBinds only
+                               -- depends on DsExpr.hi-boot.
 
 import Bag             ( isEmptyBag )
 import BasicTypes       ( Module )
 import CmdLineOpts     ( opt_SccGroup, opt_SccProfilingOn )
-import CoreLift                ( liftCoreBindings )
-import CoreLint                ( lintCoreBindings )
-import Id              ( nullIdEnv, GenId, Id )
-import ErrUtils                ( dumpIfSet, doIfSet )
+import CoreLint                ( beginPass, endPass )
+import ErrUtils                ( doIfSet )
 import Outputable
 import UniqSupply      ( splitUniqSupply, UniqSupply )
 \end{code}
@@ -35,42 +33,38 @@ start.
 
 \begin{code}
 deSugar :: UniqSupply          -- name supply
+        -> GlobalValueEnv      -- value env
        -> Module               -- module name
        -> TypecheckedMonoBinds
        -> [TypecheckedForeignDecl]
-       -> IO ([CoreBinding], SDoc, SDoc, SDoc) -- output
-
-deSugar us mod_name all_binds fo_decls
-  = let
-       (us1, us2) = splitUniqSupply us
-       (us3, us4) = splitUniqSupply us2
-
-        module_and_group = (mod_name, grp_name)
-       grp_name  = case opt_SccGroup of
-                       Just xx -> _PK_ xx
-                       Nothing -> mod_name     -- default: module name
+       -> IO ([CoreBind], SDoc, SDoc) -- output
 
-       (core_prs, ds_warns) = initDs us1 nullIdEnv module_and_group 
-                              (dsMonoBinds opt_SccProfilingOn all_binds [])
+deSugar us global_val_env mod_name all_binds fo_decls = do
+       beginPass "Desugar"
+       -- Do desugaring
+       let (core_prs, ds_warns) = initDs us1 global_val_env module_and_group 
+                                           (dsMonoBinds opt_SccProfilingOn all_binds [])
+            ds_binds' = [Rec core_prs]
 
-       ((fi_binds, fe_binds, hc_code, h_code, c_code), ds_warns2) = 
-                  initDs us3 nullIdEnv module_and_group 
-                        (dsForeigns fo_decls)
+           ((fi_binds, fe_binds, h_code, c_code), ds_warns2) = 
+                   initDs us3 global_val_env module_and_group (dsForeigns fo_decls)
 
-       ds_binds' = liftCoreBindings us4 [Rec (core_prs)]
-       ds_binds  = fi_binds ++ ds_binds' ++ fe_binds
-    in
+           ds_binds  = fi_binds ++ ds_binds' ++ fe_binds
 
-       -- Display any warnings
-    doIfSet (not (isEmptyBag ds_warns))
-       (printErrs (pprDsWarnings ds_warns)) >>
+        -- Display any warnings
+        doIfSet (not (isEmptyBag ds_warns))
+               (printErrs (pprDsWarnings ds_warns))
 
-       -- Lint result if necessary
-    lintCoreBindings "Desugarer" False ds_binds >>
+        -- Lint result if necessary
+        endPass "Desugar" opt_D_dump_ds ds_binds
+        return (ds_binds, h_code, c_code)
+  where
+    (us1, us2) = splitUniqSupply us
+    (us3, us4) = splitUniqSupply us2
 
-       -- Dump output
-    dumpIfSet opt_D_dump_ds "Desugared:"
-       (pprCoreBindings ds_binds)      >>
+    module_and_group = (mod_name, grp_name)
+    grp_name  = case opt_SccGroup of
+                 Just xx -> _PK_ xx
+                 Nothing -> mod_name   -- default: module name
 
-    return (ds_binds, hc_code, h_code, c_code)
 \end{code}