[project @ 2005-03-31 16:11:49 by simonmar]
[ghc-hetmet.git] / ghc / compiler / main / DriverPipeline.hs
index f9fdafa..fae03ac 100644 (file)
@@ -20,7 +20,9 @@ module DriverPipeline (
    link, 
 
         -- DLL building
-   doMkDLL
+   doMkDLL,
+
+   getOptionsFromStringBuffer, -- used in module GHC
   ) where
 
 #include "HsVersions.h"
@@ -46,11 +48,12 @@ import StringBuffer ( hGetStringBuffer )
 import BasicTypes      ( SuccessFlag(..) )
 import Maybes          ( expectJust )
 import Ctype           ( is_ident )
-
-import ParserCoreUtils ( getCoreModuleName )
+import StringBuffer    ( StringBuffer(..), lexemeToString )
+import ParserCoreUtils ( getCoreModuleName )
 
 import EXCEPTION
 import DATA_IOREF      ( readIORef, writeIORef, IORef )
+import GLAEXTS         ( Int(..) )
 
 import Directory
 import System
@@ -87,27 +90,28 @@ preprocess dflags filename =
 
 compile :: HscEnv
        -> ModSummary
-       -> Bool                 -- True <=> source unchanged
-       -> Bool                 -- True <=> have object
+       -> Maybe Linkable       -- Just linkable <=> source unchanged
         -> Maybe ModIface       -- Old interface, if available
         -> IO CompResult
 
 data CompResult
-   = CompOK   ModDetails               -- New details
-              ModIface                 -- New iface
-              (Maybe Linkable) -- New code; Nothing => compilation was not reqd
-                               --                      (old code is still valid)
+   = CompOK   ModDetails       -- New details
+              ModIface         -- New iface
+              (Maybe Linkable) -- a Maybe, for the same reasons as hm_linkable
 
    | CompErrs 
 
 
-compile hsc_env mod_summary
-       source_unchanged have_object old_iface = do 
+compile hsc_env mod_summary maybe_old_linkable old_iface = do 
 
    let dflags0     = hsc_dflags hsc_env
        this_mod    = ms_mod mod_summary
        src_flavour = ms_hsc_src mod_summary
 
+       have_object 
+              | Just l <- maybe_old_linkable, isObjectLinkable l = True
+              | otherwise = False
+
    showPass dflags0 ("Compiling " ++ showModMsg have_object mod_summary)
 
    let verb      = verbosity dflags0
@@ -115,12 +119,13 @@ compile hsc_env mod_summary
    let input_fn   = expectJust "compile:hs" (ml_hs_file location) 
    let input_fnpp = expectJust "compile:hspp" (ms_hspp_file mod_summary)
 
-   when (verb >= 2) (hPutStrLn stderr ("compile: input file " ++ input_fnpp))
+   when (verb >= 2) (putMsg ("compile: input file " ++ input_fnpp))
 
    -- Add in the OPTIONS from the source file
    -- This is nasty: we've done this once already, in the compilation manager
    -- It might be better to cache the flags in the ml_hspp_file field,say
-   opts <- getOptionsFromSource input_fnpp
+   let hspp_buf = expectJust "compile:hspp_buf" (ms_hspp_buf mod_summary)
+       opts = getOptionsFromStringBuffer hspp_buf
    (dflags1,unhandled_flags) <- parseDynamicFlags dflags0 opts
    checkProcessArgsResult unhandled_flags input_fn
 
@@ -149,17 +154,19 @@ compile hsc_env mod_summary
 
    -- -no-recomp should also work with --make
    let do_recomp = dopt Opt_RecompChecking dflags
-       source_unchanged' = source_unchanged && do_recomp
+       source_unchanged = isJust maybe_old_linkable && do_recomp
        hsc_env' = hsc_env { hsc_dflags = dflags' }
 
    -- run the compiler
    hsc_result <- hscMain hsc_env' printErrorsAndWarnings mod_summary
-                        source_unchanged' have_object old_iface
+                        source_unchanged have_object old_iface
 
    case hsc_result of
       HscFail -> return CompErrs
 
-      HscNoRecomp details iface -> return (CompOK details iface Nothing)
+      HscNoRecomp details iface -> 
+         ASSERT(isJust maybe_old_linkable)
+         return (CompOK details iface maybe_old_linkable)
 
       HscRecomp details iface
                stub_h_exists stub_c_exists maybe_interpreted_code 
@@ -169,7 +176,6 @@ compile hsc_env mod_summary
 
        | otherwise             -- Normal Haskell source files
        -> do
-          let 
           maybe_stub_o <- compileStub dflags' stub_c_exists
           let stub_unlinked = case maybe_stub_o of
                                  Nothing -> []
@@ -244,6 +250,9 @@ link Interactive dflags batch_attempt_linking hpt
         return Succeeded
 #endif
 
+link JustTypecheck dflags batch_attempt_linking hpt
+   = return Succeeded
+
 link BatchCompile dflags batch_attempt_linking hpt
    | batch_attempt_linking
    = do 
@@ -254,7 +263,7 @@ link BatchCompile dflags batch_attempt_linking hpt
            pkg_deps  = concatMap (dep_pkgs . mi_deps . hm_iface) home_mod_infos
 
            -- the linkables to link
-           linkables = map hm_linkable home_mod_infos
+           linkables = map (fromJust.hm_linkable) home_mod_infos
 
         when (verb >= 3) $ do
             hPutStrLn stderr "link: linkables are ..."
@@ -648,6 +657,7 @@ runPhase (Hsc src_flavour) stop dflags0 basename suff input_fn get_output_fn _ma
                                        ms_hspp_buf  = hspp_buf,
                                        ms_location  = location4,
                                        ms_hs_date   = src_timestamp,
+                                       ms_obj_date  = Nothing,
                                        ms_imps      = unused_field,
                                        ms_srcimps   = unused_field }
 
@@ -1079,13 +1089,14 @@ staticLink dflags o_files dep_packages = do
     pkg_framework_paths <- getPackageFrameworkPath dflags dep_packages
     let pkg_framework_path_opts = map ("-F"++) pkg_framework_paths
 
-    framework_paths <- readIORef v_Framework_paths
-    let framework_path_opts = map ("-F"++) framework_paths
+    let framework_paths = frameworkPaths dflags
+        framework_path_opts = map ("-F"++) framework_paths
 
     pkg_frameworks <- getPackageFrameworks dflags dep_packages
     let pkg_framework_opts = concat [ ["-framework", fw] | fw <- pkg_frameworks ]
-    frameworks <- readIORef v_Cmdline_frameworks
-    let framework_opts = concat [ ["-framework", fw] | fw <- reverse frameworks ]
+    
+    let frameworks = cmdlineFrameworks dflags
+        framework_opts = concat [ ["-framework", fw] | fw <- reverse frameworks ]
         -- reverse because they're added in reverse order from the cmd line
 #endif
 
@@ -1299,6 +1310,24 @@ getOptionsFromSource file
                               return (opts ++ rest)
                       | otherwise -> return []
 
+getOptionsFromStringBuffer :: StringBuffer -> [String]
+getOptionsFromStringBuffer buffer@(StringBuffer _ len# _) = 
+  let 
+       ls = lines (lexemeToString buffer (I# len#))  -- lazy, so it's ok
+  in
+  look ls
+  where
+       look [] = []
+       look (l':ls) = do
+           let l = removeSpaces l'
+           case () of
+               () | null l -> look ls
+                  | prefixMatch "#" l -> look ls
+                  | prefixMatch "{-# LINE" l -> look ls   -- -}
+                  | Just opts <- matchOptions l
+                       -> opts ++ look ls
+                  | otherwise -> []
+
 -- detect {-# OPTIONS_GHC ... #-}.  For the time being, we accept OPTIONS
 -- instead of OPTIONS_GHC, but that is deprecated.
 matchOptions s