[project @ 1999-06-23 10:33:03 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / Main.lhs
index 0eb036c..9a62fae 100644 (file)
@@ -12,7 +12,13 @@ import IO            ( hPutStr, stderr )
 import HsSyn
 import BasicTypes      ( NewOrData(..) )
 
-import ReadPrefix      ( rdModule )
+import RdrHsSyn                ( RdrNameHsModule )
+import FastString      ( mkFastCharString, unpackFS )
+import StringBuffer    ( hGetStringBuffer )
+import Parser          ( parse )
+import Lex             ( PState(..), P, ParseResult(..) )
+import SrcLoc          ( mkSrcLoc )
+
 import Rename          ( renameModule )
 
 import MkIface         ( startIface, ifaceDecls, endIface )
@@ -55,18 +61,43 @@ main =
 \end{code}
 
 \begin{code}
+parseModule :: IO (ModuleName, RdrNameHsModule)
+parseModule = do
+    buf <- hGetStringBuffer True{-expand tabs-} (unpackFS src_filename)
+    case parse buf PState{ bol = 0#, atbol = 1#,
+                          context = [], glasgow_exts = glaexts,
+                          loc = mkSrcLoc src_filename 1 } of
+
+       PFailed err -> do
+               printErrs err
+               ghcExit 1
+               return (error "parseModule") -- just to get the types right
+
+       POk _ m@(HsModule mod _ _ _ _ _) -> 
+               return (mod, m)
+  where
+       glaexts | opt_GlasgowExts = 1#
+               | otherwise       = 0#
+\end{code}
+
+\begin{code}
 doIt :: ([CoreToDo], [StgToDo]) -> IO ()
 
 doIt (core_cmds, stg_cmds)
   = doIfSet opt_Verbose 
        (hPutStr stderr "Glasgow Haskell Compiler, version "    >>
         hPutStr stderr compiler_version                        >>
-        hPutStr stderr ", for Haskell 98\n")                   >>
+        hPutStr stderr ", for Haskell 98\n"                    >>
+        hPutStr stderr "\tcompiled by GHC version "            >>
+        hPutStr stderr booter_version                          >>
+        hPutStr stderr "\n")                                   >>
 
        --------------------------  Reader  ----------------
-    show_pass "Reader" >>
-    _scc_     "Reader"
-    rdModule           >>= \ (mod_name, rdr_module) ->
+    show_pass "Parser" >>
+    _scc_     "Parser"
+    parseModule                >>= \ (mod_name, rdr_module) ->
+
+    dumpIfSet opt_D_dump_parsed "Parser" (ppr rdr_module) >>
 
     dumpIfSet opt_D_source_stats "Source Statistics"
        (ppSourceStats False rdr_module)                >>
@@ -332,6 +363,11 @@ compiler_version =
   go ls@[x,y] = '.':ls
   go (x:xs)   = x:go xs
 
+booter_version
+ = case "\ 
+       \ __GLASGOW_HASKELL__" of
+    ' ':n:ns -> n:'.':ns
+    ' ':m    -> m
 \end{code}
 
 \begin{code}