1 -----------------------------------------------------------------------------
5 -- (c) The University of Glasgow 2005
7 -----------------------------------------------------------------------------
9 module DriverPipeline (
10 -- Run a series of compilation steps in a pipeline, for a
11 -- collection of source files.
14 -- Interfaces for the batch-mode driver
17 -- Interfaces for the compilation manager (interpreted/batch-mode)
19 compile, CompResult(..),
25 getOptionsFromStringBuffer, -- used in module GHC
26 optionsErrorMsgs, -- ditto
29 #include "HsVersions.h"
34 import SysTools ( newTempName, addFilesToClean, getSysMan, copy )
35 import qualified SysTools
43 import StaticFlags ( v_Ld_inputs, opt_Static, WayName(..) )
47 import StringBuffer ( hGetStringBuffer )
48 import BasicTypes ( SuccessFlag(..) )
49 import Maybes ( expectJust )
50 import Ctype ( is_ident )
51 import StringBuffer ( StringBuffer(..), lexemeToString )
52 import ParserCoreUtils ( getCoreModuleName )
53 import SrcLoc ( srcLocSpan, mkSrcLoc )
54 import FastString ( mkFastString )
55 import Bag ( listToBag, emptyBag )
56 import SrcLoc ( Located(..) )
59 import DATA_IOREF ( readIORef, writeIORef, IORef )
60 import GLAEXTS ( Int(..) )
69 -- ---------------------------------------------------------------------------
72 -- Just preprocess a file, put the result in a temp. file (used by the
73 -- compilation manager during the summary phase).
75 -- We return the augmented DynFlags, because they contain the result
76 -- of slurping in the OPTIONS pragmas
78 preprocess :: DynFlags -> (FilePath, Maybe Phase) -> IO (DynFlags, FilePath)
79 preprocess dflags (filename, mb_phase) =
80 ASSERT2(isJust mb_phase || isHaskellSrcFilename filename, text filename)
81 runPipeline anyHsc dflags (filename, mb_phase) Temporary Nothing{-no ModLocation-}
83 -- ---------------------------------------------------------------------------
86 -- Compile a single module, under the control of the compilation manager.
88 -- This is the interface between the compilation manager and the
89 -- compiler proper (hsc), where we deal with tedious details like
90 -- reading the OPTIONS pragma from the source file, and passing the
91 -- output of hsc through the C compiler.
93 -- NB. No old interface can also mean that the source has changed.
96 -> (Messages -> IO ()) -- error message callback
98 -> Maybe Linkable -- Just linkable <=> source unchanged
99 -> Maybe ModIface -- Old interface, if available
104 = CompOK ModDetails -- New details
105 ModIface -- New iface
106 (Maybe Linkable) -- a Maybe, for the same reasons as hm_linkable
111 compile hsc_env msg_act mod_summary maybe_old_linkable old_iface mod_index nmods = do
113 let dflags0 = hsc_dflags hsc_env
114 this_mod = ms_mod mod_summary
115 src_flavour = ms_hsc_src mod_summary
118 | Just l <- maybe_old_linkable, isObjectLinkable l = True
121 showPass dflags0 ("Compiling " ++ showModMsg have_object mod_summary)
123 let location = ms_location mod_summary
124 let input_fn = expectJust "compile:hs" (ml_hs_file location)
125 let input_fnpp = expectJust "compile:hspp" (ms_hspp_file mod_summary)
127 debugTraceMsg dflags0 2 ("compile: input file " ++ input_fnpp)
129 -- Add in the OPTIONS from the source file
130 -- This is nasty: we've done this once already, in the compilation manager
131 -- It might be better to cache the flags in the ml_hspp_file field,say
132 let hspp_buf = expectJust "compile:hspp_buf" (ms_hspp_buf mod_summary)
133 opts = getOptionsFromStringBuffer hspp_buf
134 (dflags1,unhandled_flags) <- parseDynamicFlags dflags0 (map snd opts)
135 if (not (null unhandled_flags))
136 then do msg_act (optionsErrorMsgs unhandled_flags opts input_fn)
140 let (basename, _) = splitFilename input_fn
142 -- We add the directory in which the .hs files resides) to the import path.
143 -- This is needed when we try to compile the .hc file later, if it
144 -- imports a _stub.h file that we created here.
145 let current_dir = directoryOf basename
146 old_paths = includePaths dflags1
147 dflags = dflags1 { includePaths = current_dir : old_paths }
149 -- Figure out what lang we're generating
150 let hsc_lang = hscMaybeAdjustTarget dflags StopLn src_flavour (hscTarget dflags)
151 -- ... and what the next phase should be
152 let next_phase = hscNextPhase dflags src_flavour hsc_lang
153 -- ... and what file to generate the output into
154 output_fn <- getOutputFilename dflags next_phase
155 Temporary basename next_phase (Just location)
157 let dflags' = dflags { hscTarget = hsc_lang,
158 hscOutName = output_fn,
159 hscStubCOutName = basename ++ "_stub.c",
160 hscStubHOutName = basename ++ "_stub.h",
161 extCoreName = basename ++ ".hcr" }
163 -- -no-recomp should also work with --make
164 let do_recomp = dopt Opt_RecompChecking dflags
165 source_unchanged = isJust maybe_old_linkable && do_recomp
166 hsc_env' = hsc_env { hsc_dflags = dflags' }
167 object_filename = ml_obj_file location
170 hsc_result <- hscMain hsc_env' msg_act mod_summary
171 source_unchanged have_object old_iface
172 (Just (mod_index, nmods))
175 HscFail -> return CompErrs
177 HscNoRecomp details iface ->
178 ASSERT(isJust maybe_old_linkable)
179 return (CompOK details iface maybe_old_linkable)
181 HscRecomp details iface stub_h_exists stub_c_exists maybe_interpreted_code
183 | isHsBoot src_flavour -- No further compilation to do
184 -> do case hsc_lang of
185 HscInterpreted -> return ()
186 _other -> SysTools.touch dflags' "Touching object file"
188 return (CompOK details iface Nothing)
190 | otherwise -- Normal source file
192 maybe_stub_o <- compileStub dflags' stub_c_exists
193 let stub_unlinked = case maybe_stub_o of
195 Just stub_o -> [ DotO stub_o ]
197 (hs_unlinked, unlinked_time) <-
200 -- in interpreted mode, just return the compiled code
201 -- as our "unlinked" object.
203 -> case maybe_interpreted_code of
205 Just comp_bc -> return ([BCOs comp_bc], ms_hs_date mod_summary)
206 -- Why do we use the timestamp of the source file here,
207 -- rather than the current time? This works better in
208 -- the case where the local clock is out of sync
209 -- with the filesystem's clock. It's just as accurate:
210 -- if the source is modified, then the linkable will
213 Nothing -> panic "compile: no interpreted code"
216 -> return ([], ms_hs_date mod_summary)
218 -- We're in --make mode: finish the compilation pipeline.
220 -> do runPipeline StopLn dflags (output_fn,Nothing) Persistent
222 -- The object filename comes from the ModLocation
224 o_time <- getModificationTime object_filename
225 return ([DotO object_filename], o_time)
227 let linkable = LM unlinked_time this_mod
228 (hs_unlinked ++ stub_unlinked)
230 return (CompOK details iface (Just linkable))
232 -----------------------------------------------------------------------------
233 -- stub .h and .c files (for foreign export support)
235 compileStub dflags stub_c_exists
236 | not stub_c_exists = return Nothing
238 -- compile the _stub.c file w/ gcc
239 let stub_c = hscStubCOutName dflags
240 (_, stub_o) <- runPipeline StopLn dflags
241 (stub_c,Nothing) Persistent Nothing{-no ModLocation-}
245 -- ---------------------------------------------------------------------------
248 link :: GhcMode -- interactive or batch
249 -> DynFlags -- dynamic flags
250 -> Bool -- attempt linking in batch mode?
251 -> HomePackageTable -- what to link
254 -- For the moment, in the batch linker, we don't bother to tell doLink
255 -- which packages to link -- it just tries all that are available.
256 -- batch_attempt_linking should only be *looked at* in batch mode. It
257 -- should only be True if the upsweep was successful and someone
258 -- exports main, i.e., we have good reason to believe that linking
262 link Interactive dflags batch_attempt_linking hpt
263 = do -- Not Linking...(demand linker will do the job)
267 link JustTypecheck dflags batch_attempt_linking hpt
270 link BatchCompile dflags batch_attempt_linking hpt
271 | batch_attempt_linking
274 home_mod_infos = moduleEnvElts hpt
276 -- the packages we depend on
277 pkg_deps = concatMap (dep_pkgs . mi_deps . hm_iface) home_mod_infos
279 -- the linkables to link
280 linkables = map (fromJust.hm_linkable) home_mod_infos
282 debugTraceMsg dflags 3 "link: linkables are ..."
283 debugTraceMsg dflags 3 (showSDoc (vcat (map ppr linkables)))
285 -- check for the -no-link flag
286 if isNoLink (ghcLink dflags)
287 then do debugTraceMsg dflags 3 "link(batch): linking omitted (-c flag given)."
291 debugTraceMsg dflags 1 "Linking ..."
293 let getOfiles (LM _ _ us) = map nameOfObject (filter isObject us)
294 obj_files = concatMap getOfiles linkables
296 -- Don't showPass in Batch mode; doLink will do that for us.
297 staticLink dflags obj_files pkg_deps
299 debugTraceMsg dflags 3 "link: done"
301 -- staticLink only returns if it succeeds
305 = do debugTraceMsg dflags 3 "link(batch): upsweep (partially) failed OR"
306 debugTraceMsg dflags 3 " Main.main not exported; not linking."
310 -- -----------------------------------------------------------------------------
311 -- Compile files in one-shot mode.
313 oneShot :: DynFlags -> Phase -> [(String, Maybe Phase)] -> IO ()
314 oneShot dflags stop_phase srcs = do
315 o_files <- mapM (compileFile dflags stop_phase) srcs
316 doLink dflags stop_phase o_files
318 compileFile :: DynFlags -> Phase -> (FilePath, Maybe Phase) -> IO FilePath
319 compileFile dflags stop_phase (src, mb_phase) = do
320 exists <- doesFileExist src
322 throwDyn (CmdLineError ("does not exist: " ++ src))
325 split = dopt Opt_SplitObjs dflags
326 mb_o_file = outputFile dflags
327 ghc_link = ghcLink dflags -- Set by -c or -no-link
329 -- When linking, the -o argument refers to the linker's output.
330 -- otherwise, we use it as the name for the pipeline's output.
332 | StopLn <- stop_phase, not (isNoLink ghc_link) = Persistent
333 -- -o foo applies to linker
334 | Just o_file <- mb_o_file = SpecificFile o_file
335 -- -o foo applies to the file we are compiling now
336 | otherwise = Persistent
338 stop_phase' = case stop_phase of
339 As | split -> SplitAs
342 (_, out_file) <- runPipeline stop_phase' dflags
343 (src, mb_phase) output Nothing{-no ModLocation-}
347 doLink :: DynFlags -> Phase -> [FilePath] -> IO ()
348 doLink dflags stop_phase o_files
349 | not (isStopLn stop_phase)
350 = return () -- We stopped before the linking phase
353 = case ghcLink dflags of
355 StaticLink -> staticLink dflags o_files link_pkgs
356 MkDLL -> doMkDLL dflags o_files link_pkgs
358 -- Always link in the haskell98 package for static linking. Other
359 -- packages have to be specified via the -package flag.
361 | ExtPackage h98_id <- haskell98PackageId (pkgState dflags) = [h98_id]
365 -- ---------------------------------------------------------------------------
366 -- Run a compilation pipeline, consisting of multiple phases.
368 -- This is the interface to the compilation pipeline, which runs
369 -- a series of compilation steps on a single source file, specifying
370 -- at which stage to stop.
372 -- The DynFlags can be modified by phases in the pipeline (eg. by
373 -- GHC_OPTIONS pragmas), and the changes affect later phases in the
378 -- output should be to a temporary file: we're going to
379 -- run more compilation steps on this output later
381 -- we want a persistent file, i.e. a file in the current directory
382 -- derived from the input filename, but with the appropriate extension.
383 -- eg. in "ghc -c Foo.hs" the output goes into ./Foo.o.
384 | SpecificFile FilePath
385 -- the output must go into the specified file.
388 :: Phase -- When to stop
389 -> DynFlags -- Dynamic flags
390 -> (FilePath,Maybe Phase) -- Input filename (and maybe -x suffix)
391 -> PipelineOutput -- Output filename
392 -> Maybe ModLocation -- A ModLocation, if this is a Haskell module
393 -> IO (DynFlags, FilePath) -- (final flags, output filename)
395 runPipeline stop_phase dflags (input_fn, mb_phase) output maybe_loc
397 let (basename, suffix) = splitFilename input_fn
399 -- If we were given a -x flag, then use that phase to start from
401 | Just x_phase <- mb_phase = x_phase
402 | otherwise = startPhase suffix
404 -- We want to catch cases of "you can't get there from here" before
405 -- we start the pipeline, because otherwise it will just run off the
408 -- There is a partial ordering on phases, where A < B iff A occurs
409 -- before B in a normal compilation pipeline.
411 when (not (start_phase `happensBefore` stop_phase)) $
413 ("cannot compile this file to desired target: "
416 -- this is a function which will be used to calculate output file names
417 -- as we go along (we partially apply it to some of its inputs here)
418 let get_output_fn = getOutputFilename dflags stop_phase output basename
420 -- Execute the pipeline...
421 (dflags', output_fn, maybe_loc) <-
422 pipeLoop dflags start_phase stop_phase input_fn
423 basename suffix get_output_fn maybe_loc
425 -- Sometimes, a compilation phase doesn't actually generate any output
426 -- (eg. the CPP phase when -fcpp is not turned on). If we end on this
427 -- stage, but we wanted to keep the output, then we have to explicitly
431 return (dflags', output_fn)
433 do final_fn <- get_output_fn stop_phase maybe_loc
434 when (final_fn /= output_fn) $
435 copy dflags ("Copying `" ++ output_fn ++ "' to `" ++ final_fn
436 ++ "'") output_fn final_fn
437 return (dflags', final_fn)
441 pipeLoop :: DynFlags -> Phase -> Phase
442 -> FilePath -> String -> Suffix
443 -> (Phase -> Maybe ModLocation -> IO FilePath)
445 -> IO (DynFlags, FilePath, Maybe ModLocation)
447 pipeLoop dflags phase stop_phase
448 input_fn orig_basename orig_suff
449 orig_get_output_fn maybe_loc
451 | phase `eqPhase` stop_phase -- All done
452 = return (dflags, input_fn, maybe_loc)
454 | not (phase `happensBefore` stop_phase)
455 -- Something has gone wrong. We'll try to cover all the cases when
456 -- this could happen, so if we reach here it is a panic.
457 -- eg. it might happen if the -C flag is used on a source file that
458 -- has {-# OPTIONS -fasm #-}.
459 = panic ("pipeLoop: at phase " ++ show phase ++
460 " but I wanted to stop at phase " ++ show stop_phase)
463 = do { (next_phase, dflags', maybe_loc, output_fn)
464 <- runPhase phase stop_phase dflags orig_basename
465 orig_suff input_fn orig_get_output_fn maybe_loc
466 ; pipeLoop dflags' next_phase stop_phase output_fn
467 orig_basename orig_suff orig_get_output_fn maybe_loc }
470 :: DynFlags -> Phase -> PipelineOutput -> String
471 -> Phase{-next phase-} -> Maybe ModLocation -> IO FilePath
472 getOutputFilename dflags stop_phase output basename
476 odir = outputDir dflags
477 osuf = objectSuf dflags
478 keep_hc = dopt Opt_KeepHcFiles dflags
479 keep_raw_s = dopt Opt_KeepRawSFiles dflags
480 keep_s = dopt Opt_KeepSFiles dflags
482 myPhaseInputExt HCc = hcsuf
483 myPhaseInputExt StopLn = osuf
484 myPhaseInputExt other = phaseInputExt other
486 func next_phase maybe_location
487 | is_last_phase, Persistent <- output = persistent_fn
488 | is_last_phase, SpecificFile f <- output = return f
489 | keep_this_output = persistent_fn
490 | otherwise = newTempName dflags suffix
492 is_last_phase = next_phase `eqPhase` stop_phase
494 -- sometimes, we keep output from intermediate stages
498 Mangle | keep_raw_s -> True
500 HCc | keep_hc -> True
503 suffix = myPhaseInputExt next_phase
505 -- persistent object files get put in odir
507 | StopLn <- next_phase = return odir_persistent
508 | otherwise = return persistent
510 persistent = basename `joinFileExt` suffix
513 | Just loc <- maybe_location = ml_obj_file loc
514 | Just d <- odir = d `joinFileName` persistent
515 | otherwise = persistent
518 -- -----------------------------------------------------------------------------
519 -- Each phase in the pipeline returns the next phase to execute, and the
520 -- name of the file in which the output was placed.
522 -- We must do things dynamically this way, because we often don't know
523 -- what the rest of the phases will be until part-way through the
524 -- compilation: for example, an {-# OPTIONS -fasm #-} at the beginning
525 -- of a source file can change the latter stages of the pipeline from
526 -- taking the via-C route to using the native code generator.
528 runPhase :: Phase -- Do this phase first
529 -> Phase -- Stop just before this phase
531 -> String -- basename of original input source
532 -> String -- its extension
533 -> FilePath -- name of file which contains the input to this phase.
534 -> (Phase -> Maybe ModLocation -> IO FilePath)
535 -- how to calculate the output filename
536 -> Maybe ModLocation -- the ModLocation, if we have one
537 -> IO (Phase, -- next phase
538 DynFlags, -- new dynamic flags
539 Maybe ModLocation, -- the ModLocation, if we have one
540 FilePath) -- output filename
542 -- Invariant: the output filename always contains the output
543 -- Interesting case: Hsc when there is no recompilation to do
544 -- Then the output filename is still a .o file
546 -------------------------------------------------------------------------------
549 runPhase (Unlit sf) _stop dflags _basename _suff input_fn get_output_fn maybe_loc
550 = do let unlit_flags = getOpts dflags opt_L
551 -- The -h option passes the file name for unlit to put in a #line directive
552 output_fn <- get_output_fn (Cpp sf) maybe_loc
554 SysTools.runUnlit dflags
555 (map SysTools.Option unlit_flags ++
556 [ SysTools.Option "-h"
557 , SysTools.Option input_fn
558 , SysTools.FileOption "" input_fn
559 , SysTools.FileOption "" output_fn
562 return (Cpp sf, dflags, maybe_loc, output_fn)
564 -------------------------------------------------------------------------------
565 -- Cpp phase : (a) gets OPTIONS out of file
566 -- (b) runs cpp if necessary
568 runPhase (Cpp sf) _stop dflags0 basename suff input_fn get_output_fn maybe_loc
569 = do src_opts <- getOptionsFromSource input_fn
570 (dflags,unhandled_flags) <- parseDynamicFlags dflags0 src_opts
571 checkProcessArgsResult unhandled_flags (basename `joinFileExt` suff)
573 if not (dopt Opt_Cpp dflags) then
574 -- no need to preprocess CPP, just pass input file along
575 -- to the next phase of the pipeline.
576 return (HsPp sf, dflags, maybe_loc, input_fn)
578 output_fn <- get_output_fn (HsPp sf) maybe_loc
579 doCpp dflags True{-raw-} False{-no CC opts-} input_fn output_fn
580 return (HsPp sf, dflags, maybe_loc, output_fn)
582 -------------------------------------------------------------------------------
585 runPhase (HsPp sf) _stop dflags basename suff input_fn get_output_fn maybe_loc
586 = do if not (dopt Opt_Pp dflags) then
587 -- no need to preprocess, just pass input file along
588 -- to the next phase of the pipeline.
589 return (Hsc sf, dflags, maybe_loc, input_fn)
591 let hspp_opts = getOpts dflags opt_F
592 let orig_fn = basename `joinFileExt` suff
593 output_fn <- get_output_fn (Hsc sf) maybe_loc
594 SysTools.runPp dflags
595 ( [ SysTools.Option orig_fn
596 , SysTools.Option input_fn
597 , SysTools.FileOption "" output_fn
599 map SysTools.Option hspp_opts
601 return (Hsc sf, dflags, maybe_loc, output_fn)
603 -----------------------------------------------------------------------------
606 -- Compilation of a single module, in "legacy" mode (_not_ under
607 -- the direction of the compilation manager).
608 runPhase (Hsc src_flavour) stop dflags0 basename suff input_fn get_output_fn _maybe_loc
609 = do -- normal Hsc mode, not mkdependHS
611 -- we add the current directory (i.e. the directory in which
612 -- the .hs files resides) to the import path, since this is
613 -- what gcc does, and it's probably what you want.
614 let current_dir = directoryOf basename
616 paths = includePaths dflags0
617 dflags = dflags0 { includePaths = current_dir : paths }
619 -- gather the imports and module name
620 (hspp_buf,mod_name) <-
622 ExtCoreFile -> do { -- no explicit imports in ExtCore input.
623 ; m <- getCoreModuleName input_fn
624 ; return (Nothing, mkModule m) }
626 other -> do { buf <- hGetStringBuffer input_fn
627 ; (_,_,L _ mod_name) <- getImports dflags buf input_fn
628 ; return (Just buf, mod_name) }
630 -- Build a ModLocation to pass to hscMain.
631 -- The source filename is rather irrelevant by now, but it's used
632 -- by hscMain for messages. hscMain also needs
633 -- the .hi and .o filenames, and this is as good a way
634 -- as any to generate them, and better than most. (e.g. takes
635 -- into accout the -osuf flags)
636 location1 <- mkHomeModLocation2 dflags mod_name basename suff
638 -- Boot-ify it if necessary
639 let location2 | isHsBoot src_flavour = addBootSuffixLocn location1
640 | otherwise = location1
643 -- Take -ohi into account if present
644 -- This can't be done in mkHomeModuleLocation because
645 -- it only applies to the module being compiles
646 let ohi = outputHi dflags
647 location3 | Just fn <- ohi = location2{ ml_hi_file = fn }
648 | otherwise = location2
650 -- Take -o into account if present
651 -- Very like -ohi, but we must *only* do this if we aren't linking
652 -- (If we're linking then the -o applies to the linked thing, not to
653 -- the object file for one module.)
654 -- Note the nasty duplication with the same computation in compileFile above
655 let expl_o_file = outputFile dflags
656 location4 | Just ofile <- expl_o_file
657 , isNoLink (ghcLink dflags)
658 = location3 { ml_obj_file = ofile }
659 | otherwise = location3
661 -- Make the ModSummary to hand to hscMain
662 src_timestamp <- getModificationTime (basename `joinFileExt` suff)
664 unused_field = panic "runPhase:ModSummary field"
665 -- Some fields are not looked at by hscMain
666 mod_summary = ModSummary { ms_mod = mod_name,
667 ms_hsc_src = src_flavour,
668 ms_hspp_file = Just input_fn,
669 ms_hspp_buf = hspp_buf,
670 ms_location = location4,
671 ms_hs_date = src_timestamp,
672 ms_obj_date = Nothing,
673 ms_imps = unused_field,
674 ms_srcimps = unused_field }
676 o_file = ml_obj_file location4 -- The real object file
679 -- Figure out if the source has changed, for recompilation avoidance.
681 -- Setting source_unchanged to True means that M.o seems
682 -- to be up to date wrt M.hs; so no need to recompile unless imports have
683 -- changed (which the compiler itself figures out).
684 -- Setting source_unchanged to False tells the compiler that M.o is out of
685 -- date wrt M.hs (or M.o doesn't exist) so we must recompile regardless.
686 let do_recomp = dopt Opt_RecompChecking dflags
688 if not do_recomp || not (isStopLn stop)
689 -- Set source_unchanged to False unconditionally if
690 -- (a) recompilation checker is off, or
691 -- (b) we aren't going all the way to .o file (e.g. ghc -S)
693 -- Otherwise look at file modification dates
694 else do o_file_exists <- doesFileExist o_file
696 then return False -- Need to recompile
697 else do t2 <- getModificationTime o_file
698 if t2 > src_timestamp
703 let hsc_lang = hscMaybeAdjustTarget dflags stop src_flavour (hscTarget dflags)
704 let next_phase = hscNextPhase dflags src_flavour hsc_lang
705 output_fn <- get_output_fn next_phase (Just location4)
707 let dflags' = dflags { hscTarget = hsc_lang,
708 hscOutName = output_fn,
709 hscStubCOutName = basename ++ "_stub.c",
710 hscStubHOutName = basename ++ "_stub.h",
711 extCoreName = basename ++ ".hcr" }
713 hsc_env <- newHscEnv dflags'
715 -- Tell the finder cache about this module
716 addHomeModuleToFinder hsc_env mod_name location4
719 result <- hscMain hsc_env printErrorsAndWarnings
720 mod_summary source_unchanged
721 False -- No object file
723 Nothing -- No "module i of n" progress info
727 HscFail -> throwDyn (PhaseFailed "hsc" (ExitFailure 1))
729 HscNoRecomp details iface -> do
730 SysTools.touch dflags' "Touching object file" o_file
731 -- The .o file must have a later modification date
732 -- than the source file (else we wouldn't be in HscNoRecomp)
733 -- but we touch it anyway, to keep 'make' happy (we think).
734 return (StopLn, dflags', Just location4, o_file)
736 HscRecomp _details _iface
737 stub_h_exists stub_c_exists
738 _maybe_interpreted_code -> do
741 maybe_stub_o <- compileStub dflags' stub_c_exists
744 Just stub_o -> consIORef v_Ld_inputs stub_o
746 -- In the case of hs-boot files, generate a dummy .o-boot
747 -- stamp file for the benefit of Make
749 HsBootFile -> SysTools.touch dflags' "Touching object file" o_file
752 return (next_phase, dflags', Just location4, output_fn)
754 -----------------------------------------------------------------------------
757 runPhase CmmCpp stop dflags basename suff input_fn get_output_fn maybe_loc
759 output_fn <- get_output_fn Cmm maybe_loc
760 doCpp dflags False{-not raw-} True{-include CC opts-} input_fn output_fn
761 return (Cmm, dflags, maybe_loc, output_fn)
763 runPhase Cmm stop dflags basename suff input_fn get_output_fn maybe_loc
765 let hsc_lang = hscMaybeAdjustTarget dflags stop HsSrcFile (hscTarget dflags)
766 let next_phase = hscNextPhase dflags HsSrcFile hsc_lang
767 output_fn <- get_output_fn next_phase maybe_loc
769 let dflags' = dflags { hscTarget = hsc_lang,
770 hscOutName = output_fn,
771 hscStubCOutName = basename ++ "_stub.c",
772 hscStubHOutName = basename ++ "_stub.h",
773 extCoreName = basename ++ ".hcr" }
775 ok <- hscCmmFile dflags' input_fn
777 when (not ok) $ throwDyn (PhaseFailed "cmm" (ExitFailure 1))
779 return (next_phase, dflags, maybe_loc, output_fn)
781 -----------------------------------------------------------------------------
784 -- we don't support preprocessing .c files (with -E) now. Doing so introduces
785 -- way too many hacks, and I can't say I've ever used it anyway.
787 runPhase cc_phase stop dflags basename suff input_fn get_output_fn maybe_loc
788 | cc_phase `eqPhase` Cc || cc_phase `eqPhase` HCc
789 = do let cc_opts = getOpts dflags opt_c
790 hcc = cc_phase `eqPhase` HCc
792 let cmdline_include_paths = includePaths dflags
794 -- HC files have the dependent packages stamped into them
795 pkgs <- if hcc then getHCFilePackages input_fn else return []
797 -- add package include paths even if we're just compiling .c
798 -- files; this is the Value Add(TM) that using ghc instead of
800 pkg_include_dirs <- getPackageIncludePath dflags pkgs
801 let include_paths = foldr (\ x xs -> "-I" : x : xs) []
802 (cmdline_include_paths ++ pkg_include_dirs)
804 let (md_c_flags, md_regd_c_flags) = machdepCCOpts dflags
805 let pic_c_flags = picCCOpts dflags
807 let verb = getVerbFlag dflags
809 pkg_extra_cc_opts <- getPackageExtraCcOpts dflags pkgs
811 let split_objs = dopt Opt_SplitObjs dflags
812 split_opt | hcc && split_objs = [ "-DUSE_SPLIT_MARKERS" ]
815 let excessPrecision = dopt Opt_ExcessPrecision dflags
819 let mangle = dopt Opt_DoAsmMangling dflags
821 | hcc && mangle = Mangle
823 output_fn <- get_output_fn next_phase maybe_loc
825 SysTools.runCc dflags (
826 -- force the C compiler to interpret this file as C when
827 -- compiling .hc files, by adding the -x c option.
828 -- Also useful for plain .c files, just in case GHC saw a
830 [ SysTools.Option "-x", SysTools.Option "c"] ++
831 [ SysTools.FileOption "" input_fn
832 , SysTools.Option "-o"
833 , SysTools.FileOption "" output_fn
835 ++ map SysTools.Option (
841 ++ [ verb, "-S", "-Wimplicit", "-O" ]
842 ++ [ "-D__GLASGOW_HASKELL__="++cProjectVersionInt ]
845 ++ (if excessPrecision then [] else [ "-ffloat-store" ])
850 return (next_phase, dflags, maybe_loc, output_fn)
852 -- ToDo: postprocess the output from gcc
854 -----------------------------------------------------------------------------
857 runPhase Mangle stop dflags _basename _suff input_fn get_output_fn maybe_loc
858 = do let mangler_opts = getOpts dflags opt_m
861 machdep_opts <- return [ show (stolen_x86_regs dflags) ]
863 machdep_opts <- return []
866 let split = dopt Opt_SplitObjs dflags
868 | split = SplitMangle
870 output_fn <- get_output_fn next_phase maybe_loc
872 SysTools.runMangle dflags (map SysTools.Option mangler_opts
873 ++ [ SysTools.FileOption "" input_fn
874 , SysTools.FileOption "" output_fn
876 ++ map SysTools.Option machdep_opts)
878 return (next_phase, dflags, maybe_loc, output_fn)
880 -----------------------------------------------------------------------------
883 runPhase SplitMangle stop dflags _basename _suff input_fn get_output_fn maybe_loc
884 = do -- tmp_pfx is the prefix used for the split .s files
885 -- We also use it as the file to contain the no. of split .s files (sigh)
886 split_s_prefix <- SysTools.newTempName dflags "split"
887 let n_files_fn = split_s_prefix
889 SysTools.runSplit dflags
890 [ SysTools.FileOption "" input_fn
891 , SysTools.FileOption "" split_s_prefix
892 , SysTools.FileOption "" n_files_fn
895 -- Save the number of split files for future references
896 s <- readFile n_files_fn
897 let n_files = read s :: Int
898 writeIORef v_Split_info (split_s_prefix, n_files)
900 -- Remember to delete all these files
901 addFilesToClean [ split_s_prefix ++ "__" ++ show n ++ ".s"
904 return (SplitAs, dflags, maybe_loc, "**splitmangle**")
905 -- we don't use the filename
907 -----------------------------------------------------------------------------
910 runPhase As stop dflags _basename _suff input_fn get_output_fn maybe_loc
911 = do let as_opts = getOpts dflags opt_a
912 let cmdline_include_paths = includePaths dflags
914 output_fn <- get_output_fn StopLn maybe_loc
916 -- we create directories for the object file, because it
917 -- might be a hierarchical module.
918 createDirectoryHierarchy (directoryOf output_fn)
920 SysTools.runAs dflags
921 (map SysTools.Option as_opts
922 ++ [ SysTools.Option ("-I" ++ p) | p <- cmdline_include_paths ]
923 ++ [ SysTools.Option "-c"
924 , SysTools.FileOption "" input_fn
925 , SysTools.Option "-o"
926 , SysTools.FileOption "" output_fn
929 return (StopLn, dflags, maybe_loc, output_fn)
932 runPhase SplitAs stop dflags basename _suff _input_fn get_output_fn maybe_loc
933 = do let as_opts = getOpts dflags opt_a
935 (split_s_prefix, n) <- readIORef v_Split_info
938 | Just d <- outputDir dflags = d
939 | otherwise = basename ++ "_split"
942 = do let input_s = split_s_prefix ++ "__" ++ show n ++ ".s"
943 let output_o = replaceFilenameDirectory
944 (basename ++ "__" ++ show n ++ ".o")
946 let osuf = objectSuf dflags
947 let real_o = replaceFilenameSuffix output_o osuf
948 SysTools.runAs dflags
949 (map SysTools.Option as_opts ++
950 [ SysTools.Option "-c"
951 , SysTools.Option "-o"
952 , SysTools.FileOption "" real_o
953 , SysTools.FileOption "" input_s
956 mapM_ assemble_file [1..n]
958 output_fn <- get_output_fn StopLn maybe_loc
959 return (StopLn, dflags, maybe_loc, output_fn)
961 -----------------------------------------------------------------------------
962 -- MoveBinary sort-of-phase
963 -- After having produced a binary, move it somewhere else and generate a
964 -- wrapper script calling the binary. Currently, we need this only in
965 -- a parallel way (i.e. in GUM), because PVM expects the binary in a
966 -- central directory.
967 -- This is called from staticLink below, after linking. I haven't made it
968 -- a separate phase to minimise interfering with other modules, and
969 -- we don't need the generality of a phase (MoveBinary is always
970 -- done after linking and makes only sense in a parallel setup) -- HWL
972 runPhase_MoveBinary input_fn
975 pvm_root <- getEnv "PVM_ROOT"
976 pvm_arch <- getEnv "PVM_ARCH"
978 pvm_executable_base = "=" ++ input_fn
979 pvm_executable = pvm_root ++ "/bin/" ++ pvm_arch ++ "/" ++ pvm_executable_base
980 -- nuke old binary; maybe use configur'ed names for cp and rm?
981 system ("rm -f " ++ pvm_executable)
982 -- move the newly created binary into PVM land
983 system ("cp -p " ++ input_fn ++ " " ++ pvm_executable)
984 -- generate a wrapper script for running a parallel prg under PVM
985 writeFile input_fn (mk_pvm_wrapper_script pvm_executable pvm_executable_base sysMan)
988 -- generates a Perl skript starting a parallel prg under PVM
989 mk_pvm_wrapper_script :: String -> String -> String -> String
990 mk_pvm_wrapper_script pvm_executable pvm_executable_base sysMan = unlines $
992 "eval 'exec perl -S $0 ${1+\"$@\"}'",
993 " if $running_under_some_shell;",
994 "# =!=!=!=!=!=!=!=!=!=!=!",
995 "# This script is automatically generated: DO NOT EDIT!!!",
996 "# Generated by Glasgow Haskell Compiler",
997 "# ngoqvam choHbogh vaj' vIHoHnISbej !!!!",
999 "$pvm_executable = '" ++ pvm_executable ++ "';",
1000 "$pvm_executable_base = '" ++ pvm_executable_base ++ "';",
1001 "$SysMan = '" ++ sysMan ++ "';",
1003 {- ToDo: add the magical shortcuts again iff we actually use them -- HWL
1004 "# first, some magical shortcuts to run "commands" on the binary",
1005 "# (which is hidden)",
1006 "if ($#ARGV == 1 && $ARGV[0] eq '+RTS' && $ARGV[1] =~ /^--((size|file|strip|rm|nm).*)/ ) {",
1007 " local($cmd) = $1;",
1008 " system("$cmd $pvm_executable");",
1009 " exit(0); # all done",
1012 "# Now, run the real binary; process the args first",
1013 "$ENV{'PE'} = $pvm_executable_base;", -- ++ pvm_executable_base,
1015 "$nprocessors = 0; # the default: as many PEs as machines in PVM config",
1016 "@nonPVM_args = ();",
1017 "$in_RTS_args = 0;",
1019 "args: while ($a = shift(@ARGV)) {",
1020 " if ( $a eq '+RTS' ) {",
1021 " $in_RTS_args = 1;",
1022 " } elsif ( $a eq '-RTS' ) {",
1023 " $in_RTS_args = 0;",
1025 " if ( $a eq '-d' && $in_RTS_args ) {",
1027 " } elsif ( $a =~ /^-qN(\\d+)/ && $in_RTS_args ) {",
1028 " $nprocessors = $1;",
1029 " } elsif ( $a =~ /^-qp(\\d+)/ && $in_RTS_args ) {",
1030 " $nprocessors = $1;",
1032 " push(@nonPVM_args, $a);",
1036 "local($return_val) = 0;",
1037 "# Start the parallel execution by calling SysMan",
1038 "system(\"$SysMan $debug $pvm_executable $nprocessors @nonPVM_args\");",
1039 "$return_val = $?;",
1040 "# ToDo: fix race condition moving files and flushing them!!",
1041 "system(\"cp $ENV{'HOME'}/$pvm_executable_base.???.gr .\") if -f \"$ENV{'HOME'}/$pvm_executable_base.002.gr\";",
1042 "exit($return_val);"
1045 -----------------------------------------------------------------------------
1046 -- Complain about non-dynamic flags in OPTIONS pragmas
1048 checkProcessArgsResult flags filename
1049 = do when (notNull flags) (throwDyn (ProgramError (
1050 showSDoc (hang (text filename <> char ':')
1051 4 (text "unknown flags in {-# OPTIONS #-} pragma:" <+>
1052 hsep (map text flags)))
1055 -----------------------------------------------------------------------------
1056 -- Look for the /* GHC_PACKAGES ... */ comment at the top of a .hc file
1058 getHCFilePackages :: FilePath -> IO [PackageId]
1059 getHCFilePackages filename =
1060 EXCEPTION.bracket (openFile filename ReadMode) hClose $ \h -> do
1063 '/':'*':' ':'G':'H':'C':'_':'P':'A':'C':'K':'A':'G':'E':'S':rest ->
1064 return (map stringToPackageId (words rest))
1068 -----------------------------------------------------------------------------
1069 -- Static linking, of .o files
1071 -- The list of packages passed to link is the list of packages on
1072 -- which this program depends, as discovered by the compilation
1073 -- manager. It is combined with the list of packages that the user
1074 -- specifies on the command line with -package flags.
1076 -- In one-shot linking mode, we can't discover the package
1077 -- dependencies (because we haven't actually done any compilation or
1078 -- read any interface files), so the user must explicitly specify all
1081 staticLink :: DynFlags -> [FilePath] -> [PackageId] -> IO ()
1082 staticLink dflags o_files dep_packages = do
1083 let verb = getVerbFlag dflags
1085 -- get the full list of packages to link with, by combining the
1086 -- explicit packages with the auto packages and all of their
1087 -- dependencies, and eliminating duplicates.
1089 let o_file = outputFile dflags
1090 #if defined(mingw32_HOST_OS)
1091 let output_fn = case o_file of { Just s -> s; Nothing -> "main.exe"; }
1093 let output_fn = case o_file of { Just s -> s; Nothing -> "a.out"; }
1096 pkg_lib_paths <- getPackageLibraryPath dflags dep_packages
1097 let pkg_lib_path_opts = map ("-L"++) pkg_lib_paths
1099 let lib_paths = libraryPaths dflags
1100 let lib_path_opts = map ("-L"++) lib_paths
1102 pkg_link_opts <- getPackageLinkOpts dflags dep_packages
1104 #ifdef darwin_TARGET_OS
1105 pkg_framework_paths <- getPackageFrameworkPath dflags dep_packages
1106 let pkg_framework_path_opts = map ("-F"++) pkg_framework_paths
1108 let framework_paths = frameworkPaths dflags
1109 framework_path_opts = map ("-F"++) framework_paths
1111 pkg_frameworks <- getPackageFrameworks dflags dep_packages
1112 let pkg_framework_opts = concat [ ["-framework", fw] | fw <- pkg_frameworks ]
1114 let frameworks = cmdlineFrameworks dflags
1115 framework_opts = concat [ ["-framework", fw] | fw <- reverse frameworks ]
1116 -- reverse because they're added in reverse order from the cmd line
1119 -- probably _stub.o files
1120 extra_ld_inputs <- readIORef v_Ld_inputs
1122 -- opts from -optl-<blah> (including -l<blah> options)
1123 let extra_ld_opts = getOpts dflags opt_l
1125 let ways = wayNames dflags
1127 -- Here are some libs that need to be linked at the *end* of
1128 -- the command line, because they contain symbols that are referred to
1129 -- by the RTS. We can't therefore use the ordinary way opts for these.
1131 debug_opts | WayDebug `elem` ways = [
1132 #if defined(HAVE_LIBBFD)
1139 thread_opts | WayThreaded `elem` ways = [
1140 #if !defined(mingw32_TARGET_OS) && !defined(freebsd_TARGET_OS)
1143 #if defined(osf3_TARGET_OS)
1149 let (md_c_flags, _) = machdepCCOpts dflags
1150 SysTools.runLink dflags (
1151 [ SysTools.Option verb
1152 , SysTools.Option "-o"
1153 , SysTools.FileOption "" output_fn
1155 ++ map SysTools.Option (
1161 #ifdef darwin_TARGET_OS
1162 ++ framework_path_opts
1165 ++ pkg_lib_path_opts
1167 #ifdef darwin_TARGET_OS
1168 ++ pkg_framework_path_opts
1169 ++ pkg_framework_opts
1175 -- parallel only: move binary to another dir -- HWL
1176 when (WayPar `elem` ways)
1177 (do success <- runPhase_MoveBinary output_fn
1178 if success then return ()
1179 else throwDyn (InstallationError ("cannot move binary to PVM dir")))
1181 -----------------------------------------------------------------------------
1182 -- Making a DLL (only for Win32)
1184 doMkDLL :: DynFlags -> [String] -> [PackageId] -> IO ()
1185 doMkDLL dflags o_files dep_packages = do
1186 let verb = getVerbFlag dflags
1187 let static = opt_Static
1188 let no_hs_main = dopt Opt_NoHsMain dflags
1189 let o_file = outputFile dflags
1190 let output_fn = case o_file of { Just s -> s; Nothing -> "HSdll.dll"; }
1192 pkg_lib_paths <- getPackageLibraryPath dflags dep_packages
1193 let pkg_lib_path_opts = map ("-L"++) pkg_lib_paths
1195 let lib_paths = libraryPaths dflags
1196 let lib_path_opts = map ("-L"++) lib_paths
1198 pkg_link_opts <- getPackageLinkOpts dflags dep_packages
1200 -- probably _stub.o files
1201 extra_ld_inputs <- readIORef v_Ld_inputs
1203 -- opts from -optdll-<blah>
1204 let extra_ld_opts = getOpts dflags opt_dll
1206 let pstate = pkgState dflags
1207 rts_id | ExtPackage id <- rtsPackageId pstate = id
1208 | otherwise = panic "staticLink: rts package missing"
1209 base_id | ExtPackage id <- basePackageId pstate = id
1210 | otherwise = panic "staticLink: base package missing"
1211 rts_pkg = getPackageDetails pstate rts_id
1212 base_pkg = getPackageDetails pstate base_id
1214 let extra_os = if static || no_hs_main
1216 else [ head (libraryDirs rts_pkg) ++ "/Main.dll_o",
1217 head (libraryDirs base_pkg) ++ "/PrelMain.dll_o" ]
1219 let (md_c_flags, _) = machdepCCOpts dflags
1220 SysTools.runMkDLL dflags
1221 ([ SysTools.Option verb
1222 , SysTools.Option "-o"
1223 , SysTools.FileOption "" output_fn
1225 ++ map SysTools.Option (
1229 ++ [ "--target=i386-mingw32" ]
1233 ++ pkg_lib_path_opts
1235 ++ (if "--def" `elem` (concatMap words extra_ld_opts)
1237 else [ "--export-all" ])
1240 -- -----------------------------------------------------------------------------
1243 doCpp :: DynFlags -> Bool -> Bool -> FilePath -> FilePath -> IO ()
1244 doCpp dflags raw include_cc_opts input_fn output_fn = do
1245 let hscpp_opts = getOpts dflags opt_P
1246 let cmdline_include_paths = includePaths dflags
1248 pkg_include_dirs <- getPackageIncludePath dflags []
1249 let include_paths = foldr (\ x xs -> "-I" : x : xs) []
1250 (cmdline_include_paths ++ pkg_include_dirs)
1252 let verb = getVerbFlag dflags
1255 | not include_cc_opts = []
1256 | otherwise = (optc ++ md_c_flags)
1258 optc = getOpts dflags opt_c
1259 (md_c_flags, _) = machdepCCOpts dflags
1261 let cpp_prog args | raw = SysTools.runCpp dflags args
1262 | otherwise = SysTools.runCc dflags (SysTools.Option "-E" : args)
1265 [ "-D" ++ HOST_OS ++ "_BUILD_OS=1",
1266 "-D" ++ HOST_ARCH ++ "_BUILD_ARCH=1",
1267 "-D" ++ TARGET_OS ++ "_HOST_OS=1",
1268 "-D" ++ TARGET_ARCH ++ "_HOST_ARCH=1" ]
1269 -- remember, in code we *compile*, the HOST is the same our TARGET,
1270 -- and BUILD is the same as our HOST.
1272 cpp_prog ([SysTools.Option verb]
1273 ++ map SysTools.Option include_paths
1274 ++ map SysTools.Option hsSourceCppOpts
1275 ++ map SysTools.Option hscpp_opts
1276 ++ map SysTools.Option cc_opts
1277 ++ map SysTools.Option target_defs
1278 ++ [ SysTools.Option "-x"
1279 , SysTools.Option "c"
1280 , SysTools.Option input_fn
1281 -- We hackily use Option instead of FileOption here, so that the file
1282 -- name is not back-slashed on Windows. cpp is capable of
1283 -- dealing with / in filenames, so it works fine. Furthermore
1284 -- if we put in backslashes, cpp outputs #line directives
1285 -- with *double* backslashes. And that in turn means that
1286 -- our error messages get double backslashes in them.
1287 -- In due course we should arrange that the lexer deals
1288 -- with these \\ escapes properly.
1289 , SysTools.Option "-o"
1290 , SysTools.FileOption "" output_fn
1293 cHaskell1Version = "5" -- i.e., Haskell 98
1295 -- Default CPP defines in Haskell source
1297 [ "-D__HASKELL1__="++cHaskell1Version
1298 , "-D__GLASGOW_HASKELL__="++cProjectVersionInt
1300 , "-D__CONCURRENT_HASKELL__"
1303 -----------------------------------------------------------------------------
1304 -- Reading OPTIONS pragmas
1306 getOptionsFromSource
1307 :: String -- input file
1308 -> IO [String] -- options, if any
1309 getOptionsFromSource file
1310 = do h <- openFile file ReadMode
1311 look h `finally` hClose h
1314 r <- tryJust ioErrors (hGetLine h)
1316 Left e | isEOFError e -> return []
1317 | otherwise -> ioError e
1319 let l = removeSpaces l'
1321 () | null l -> look h
1322 | prefixMatch "#" l -> look h
1323 | prefixMatch "{-# LINE" l -> look h -- -}
1324 | Just opts <- matchOptions l
1325 -> do rest <- look h
1326 return (opts ++ rest)
1327 | otherwise -> return []
1329 getOptionsFromStringBuffer :: StringBuffer -> [(Int,String)]
1330 getOptionsFromStringBuffer buffer@(StringBuffer _ len# _) =
1332 ls = lines (lexemeToString buffer (I# len#)) -- lazy, so it's ok
1338 let l = removeSpaces l'
1340 () | null l -> look (i+1) ls
1341 | prefixMatch "#" l -> look (i+1) ls
1342 | prefixMatch "{-# LINE" l -> look (i+1) ls -- -}
1343 | Just opts <- matchOptions l
1344 -> zip (repeat i) opts ++ look (i+1) ls
1347 -- detect {-# OPTIONS_GHC ... #-}. For the time being, we accept OPTIONS
1348 -- instead of OPTIONS_GHC, but that is deprecated.
1350 | Just s1 <- maybePrefixMatch "{-#" s -- -}
1351 = matchOptions1 (removeSpaces s1)
1356 | Just s2 <- maybePrefixMatch "OPTIONS" s
1358 _ | Just s3 <- maybePrefixMatch "_GHC" s2, not (is_ident (head s3))
1360 | not (is_ident (head s2))
1363 -> Just [] -- OPTIONS_anything is ignored, not treated as start of source
1364 | Just s2 <- maybePrefixMatch "INCLUDE" s, not (is_ident (head s2)),
1365 Just s3 <- maybePrefixMatch "}-#" (reverse s2)
1366 = Just ["-#include", removeSpaces (reverse s3)]
1367 | otherwise = Nothing
1369 | Just s3 <- maybePrefixMatch "}-#" (reverse s) = Just (words (reverse s3))
1370 | otherwise = Nothing
1373 optionsErrorMsgs :: [String] -> [(Int,String)] -> FilePath -> Messages
1374 optionsErrorMsgs unhandled_flags flags_lines filename
1375 = (emptyBag, listToBag (map mkMsg unhandled_flags_lines))
1377 unhandled_flags_lines = [ (l,f) | f <- unhandled_flags,
1378 (l,f') <- flags_lines, f == f' ]
1380 ErrUtils.mkPlainErrMsg (srcLocSpan loc) $
1381 text "unknown flag in {-# OPTIONS #-} pragma:" <+> text flag
1383 loc = mkSrcLoc (mkFastString filename) line 0
1384 -- ToDo: we need a better SrcSpan here
1386 -- -----------------------------------------------------------------------------
1389 hscNextPhase :: DynFlags -> HscSource -> HscTarget -> Phase
1390 hscNextPhase dflags HsBootFile hsc_lang = StopLn
1391 hscNextPhase dflags other hsc_lang =
1394 HscAsm | dopt Opt_SplitObjs dflags -> SplitMangle
1396 HscNothing -> StopLn
1397 HscInterpreted -> StopLn
1401 hscMaybeAdjustTarget :: DynFlags -> Phase -> HscSource -> HscTarget -> HscTarget
1402 hscMaybeAdjustTarget dflags stop HsBootFile current_hsc_lang
1403 = HscNothing -- No output (other than Foo.hi-boot) for hs-boot files
1404 hscMaybeAdjustTarget dflags stop other current_hsc_lang
1407 keep_hc = dopt Opt_KeepHcFiles dflags
1409 -- don't change the lang if we're interpreting
1410 | current_hsc_lang == HscInterpreted = current_hsc_lang
1412 -- force -fvia-C if we are being asked for a .hc file
1413 | HCc <- stop = HscC
1415 -- otherwise, stick to the plan
1416 | otherwise = current_hsc_lang
1418 GLOBAL_VAR(v_Split_info, ("",0), (String,Int))
1419 -- The split prefix and number of files