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(..) )
45 import RdrName ( GlobalRdrEnv )
48 import StringBuffer ( hGetStringBuffer )
49 import BasicTypes ( SuccessFlag(..) )
50 import Maybes ( expectJust )
51 import Ctype ( is_ident )
52 import StringBuffer ( StringBuffer(..), lexemeToString )
53 import ParserCoreUtils ( getCoreModuleName )
54 import SrcLoc ( srcLocSpan, mkSrcLoc )
55 import FastString ( mkFastString )
56 import Bag ( listToBag, emptyBag )
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"
215 -- We're in --make mode: finish the compilation pipeline.
217 -> do runPipeline StopLn dflags (output_fn,Nothing) Persistent
219 -- The object filename comes from the ModLocation
221 o_time <- getModificationTime object_filename
222 return ([DotO object_filename], o_time)
224 let linkable = LM unlinked_time this_mod
225 (hs_unlinked ++ stub_unlinked)
227 return (CompOK details iface (Just linkable))
229 -----------------------------------------------------------------------------
230 -- stub .h and .c files (for foreign export support)
232 compileStub dflags stub_c_exists
233 | not stub_c_exists = return Nothing
235 -- compile the _stub.c file w/ gcc
236 let stub_c = hscStubCOutName dflags
237 (_, stub_o) <- runPipeline StopLn dflags
238 (stub_c,Nothing) Persistent Nothing{-no ModLocation-}
242 -- ---------------------------------------------------------------------------
245 link :: GhcMode -- interactive or batch
246 -> DynFlags -- dynamic flags
247 -> Bool -- attempt linking in batch mode?
248 -> HomePackageTable -- what to link
251 -- For the moment, in the batch linker, we don't bother to tell doLink
252 -- which packages to link -- it just tries all that are available.
253 -- batch_attempt_linking should only be *looked at* in batch mode. It
254 -- should only be True if the upsweep was successful and someone
255 -- exports main, i.e., we have good reason to believe that linking
259 link Interactive dflags batch_attempt_linking hpt
260 = do -- Not Linking...(demand linker will do the job)
264 link JustTypecheck dflags batch_attempt_linking hpt
267 link BatchCompile dflags batch_attempt_linking hpt
268 | batch_attempt_linking
271 home_mod_infos = moduleEnvElts hpt
273 -- the packages we depend on
274 pkg_deps = concatMap (dep_pkgs . mi_deps . hm_iface) home_mod_infos
276 -- the linkables to link
277 linkables = map (fromJust.hm_linkable) home_mod_infos
279 debugTraceMsg dflags 3 "link: linkables are ..."
280 debugTraceMsg dflags 3 (showSDoc (vcat (map ppr linkables)))
282 -- check for the -no-link flag
283 if isNoLink (ghcLink dflags)
284 then do debugTraceMsg dflags 3 "link(batch): linking omitted (-c flag given)."
288 debugTraceMsg dflags 1 "Linking ..."
290 let getOfiles (LM _ _ us) = map nameOfObject (filter isObject us)
291 obj_files = concatMap getOfiles linkables
293 -- Don't showPass in Batch mode; doLink will do that for us.
294 staticLink dflags obj_files pkg_deps
296 debugTraceMsg dflags 3 "link: done"
298 -- staticLink only returns if it succeeds
302 = do debugTraceMsg dflags 3 "link(batch): upsweep (partially) failed OR"
303 debugTraceMsg dflags 3 " Main.main not exported; not linking."
307 -- -----------------------------------------------------------------------------
308 -- Compile files in one-shot mode.
310 oneShot :: DynFlags -> Phase -> [(String, Maybe Phase)] -> IO ()
311 oneShot dflags stop_phase srcs = do
312 o_files <- mapM (compileFile dflags stop_phase) srcs
313 doLink dflags stop_phase o_files
315 compileFile :: DynFlags -> Phase -> (FilePath, Maybe Phase) -> IO FilePath
316 compileFile dflags stop_phase (src, mb_phase) = do
317 exists <- doesFileExist src
319 throwDyn (CmdLineError ("does not exist: " ++ src))
322 split = dopt Opt_SplitObjs dflags
323 mb_o_file = outputFile dflags
324 ghc_link = ghcLink dflags -- Set by -c or -no-link
326 -- When linking, the -o argument refers to the linker's output.
327 -- otherwise, we use it as the name for the pipeline's output.
329 | StopLn <- stop_phase, not (isNoLink ghc_link) = Persistent
330 -- -o foo applies to linker
331 | Just o_file <- mb_o_file = SpecificFile o_file
332 -- -o foo applies to the file we are compiling now
333 | otherwise = Persistent
335 stop_phase' = case stop_phase of
336 As | split -> SplitAs
339 (_, out_file) <- runPipeline stop_phase' dflags
340 (src, mb_phase) output Nothing{-no ModLocation-}
344 doLink :: DynFlags -> Phase -> [FilePath] -> IO ()
345 doLink dflags stop_phase o_files
346 | not (isStopLn stop_phase)
347 = return () -- We stopped before the linking phase
350 = case ghcLink dflags of
352 StaticLink -> staticLink dflags o_files link_pkgs
353 MkDLL -> doMkDLL dflags o_files link_pkgs
355 -- Always link in the haskell98 package for static linking. Other
356 -- packages have to be specified via the -package flag.
358 | ExtPackage h98_id <- haskell98PackageId (pkgState dflags) = [h98_id]
362 -- ---------------------------------------------------------------------------
363 -- Run a compilation pipeline, consisting of multiple phases.
365 -- This is the interface to the compilation pipeline, which runs
366 -- a series of compilation steps on a single source file, specifying
367 -- at which stage to stop.
369 -- The DynFlags can be modified by phases in the pipeline (eg. by
370 -- GHC_OPTIONS pragmas), and the changes affect later phases in the
375 -- output should be to a temporary file: we're going to
376 -- run more compilation steps on this output later
378 -- we want a persistent file, i.e. a file in the current directory
379 -- derived from the input filename, but with the appropriate extension.
380 -- eg. in "ghc -c Foo.hs" the output goes into ./Foo.o.
381 | SpecificFile FilePath
382 -- the output must go into the specified file.
385 :: Phase -- When to stop
386 -> DynFlags -- Dynamic flags
387 -> (FilePath,Maybe Phase) -- Input filename (and maybe -x suffix)
388 -> PipelineOutput -- Output filename
389 -> Maybe ModLocation -- A ModLocation, if this is a Haskell module
390 -> IO (DynFlags, FilePath) -- (final flags, output filename)
392 runPipeline stop_phase dflags (input_fn, mb_phase) output maybe_loc
394 let (basename, suffix) = splitFilename input_fn
396 -- If we were given a -x flag, then use that phase to start from
398 | Just x_phase <- mb_phase = x_phase
399 | otherwise = startPhase suffix
401 -- We want to catch cases of "you can't get there from here" before
402 -- we start the pipeline, because otherwise it will just run off the
405 -- There is a partial ordering on phases, where A < B iff A occurs
406 -- before B in a normal compilation pipeline.
408 when (not (start_phase `happensBefore` stop_phase)) $
410 ("cannot compile this file to desired target: "
413 -- this is a function which will be used to calculate output file names
414 -- as we go along (we partially apply it to some of its inputs here)
415 let get_output_fn = getOutputFilename dflags stop_phase output basename
417 -- Execute the pipeline...
418 (dflags', output_fn, maybe_loc) <-
419 pipeLoop dflags start_phase stop_phase input_fn
420 basename suffix get_output_fn maybe_loc
422 -- Sometimes, a compilation phase doesn't actually generate any output
423 -- (eg. the CPP phase when -fcpp is not turned on). If we end on this
424 -- stage, but we wanted to keep the output, then we have to explicitly
428 return (dflags', output_fn)
430 do final_fn <- get_output_fn stop_phase maybe_loc
431 when (final_fn /= output_fn) $
432 copy dflags ("Copying `" ++ output_fn ++ "' to `" ++ final_fn
433 ++ "'") output_fn final_fn
434 return (dflags', final_fn)
438 pipeLoop :: DynFlags -> Phase -> Phase
439 -> FilePath -> String -> Suffix
440 -> (Phase -> Maybe ModLocation -> IO FilePath)
442 -> IO (DynFlags, FilePath, Maybe ModLocation)
444 pipeLoop dflags phase stop_phase
445 input_fn orig_basename orig_suff
446 orig_get_output_fn maybe_loc
448 | phase `eqPhase` stop_phase -- All done
449 = return (dflags, input_fn, maybe_loc)
451 | not (phase `happensBefore` stop_phase)
452 -- Something has gone wrong. We'll try to cover all the cases when
453 -- this could happen, so if we reach here it is a panic.
454 -- eg. it might happen if the -C flag is used on a source file that
455 -- has {-# OPTIONS -fasm #-}.
456 = panic ("pipeLoop: at phase " ++ show phase ++
457 " but I wanted to stop at phase " ++ show stop_phase)
460 = do { (next_phase, dflags', maybe_loc, output_fn)
461 <- runPhase phase stop_phase dflags orig_basename
462 orig_suff input_fn orig_get_output_fn maybe_loc
463 ; pipeLoop dflags' next_phase stop_phase output_fn
464 orig_basename orig_suff orig_get_output_fn maybe_loc }
467 :: DynFlags -> Phase -> PipelineOutput -> String
468 -> Phase{-next phase-} -> Maybe ModLocation -> IO FilePath
469 getOutputFilename dflags stop_phase output basename
473 odir = outputDir dflags
474 osuf = objectSuf dflags
475 keep_hc = dopt Opt_KeepHcFiles dflags
476 keep_raw_s = dopt Opt_KeepRawSFiles dflags
477 keep_s = dopt Opt_KeepSFiles dflags
479 myPhaseInputExt HCc = hcsuf
480 myPhaseInputExt StopLn = osuf
481 myPhaseInputExt other = phaseInputExt other
483 func next_phase maybe_location
484 | is_last_phase, Persistent <- output = persistent_fn
485 | is_last_phase, SpecificFile f <- output = return f
486 | keep_this_output = persistent_fn
487 | otherwise = newTempName dflags suffix
489 is_last_phase = next_phase `eqPhase` stop_phase
491 -- sometimes, we keep output from intermediate stages
495 Mangle | keep_raw_s -> True
497 HCc | keep_hc -> True
500 suffix = myPhaseInputExt next_phase
502 -- persistent object files get put in odir
504 | StopLn <- next_phase = return odir_persistent
505 | otherwise = return persistent
507 persistent = basename `joinFileExt` suffix
510 | Just loc <- maybe_location = ml_obj_file loc
511 | Just d <- odir = replaceFilenameDirectory persistent d
512 | otherwise = persistent
515 -- -----------------------------------------------------------------------------
516 -- Each phase in the pipeline returns the next phase to execute, and the
517 -- name of the file in which the output was placed.
519 -- We must do things dynamically this way, because we often don't know
520 -- what the rest of the phases will be until part-way through the
521 -- compilation: for example, an {-# OPTIONS -fasm #-} at the beginning
522 -- of a source file can change the latter stages of the pipeline from
523 -- taking the via-C route to using the native code generator.
525 runPhase :: Phase -- Do this phase first
526 -> Phase -- Stop just before this phase
528 -> String -- basename of original input source
529 -> String -- its extension
530 -> FilePath -- name of file which contains the input to this phase.
531 -> (Phase -> Maybe ModLocation -> IO FilePath)
532 -- how to calculate the output filename
533 -> Maybe ModLocation -- the ModLocation, if we have one
534 -> IO (Phase, -- next phase
535 DynFlags, -- new dynamic flags
536 Maybe ModLocation, -- the ModLocation, if we have one
537 FilePath) -- output filename
539 -- Invariant: the output filename always contains the output
540 -- Interesting case: Hsc when there is no recompilation to do
541 -- Then the output filename is still a .o file
543 -------------------------------------------------------------------------------
546 runPhase (Unlit sf) _stop dflags _basename _suff input_fn get_output_fn maybe_loc
547 = do let unlit_flags = getOpts dflags opt_L
548 -- The -h option passes the file name for unlit to put in a #line directive
549 output_fn <- get_output_fn (Cpp sf) maybe_loc
551 SysTools.runUnlit dflags
552 (map SysTools.Option unlit_flags ++
553 [ SysTools.Option "-h"
554 , SysTools.Option input_fn
555 , SysTools.FileOption "" input_fn
556 , SysTools.FileOption "" output_fn
559 return (Cpp sf, dflags, maybe_loc, output_fn)
561 -------------------------------------------------------------------------------
562 -- Cpp phase : (a) gets OPTIONS out of file
563 -- (b) runs cpp if necessary
565 runPhase (Cpp sf) _stop dflags0 basename suff input_fn get_output_fn maybe_loc
566 = do src_opts <- getOptionsFromSource input_fn
567 (dflags,unhandled_flags) <- parseDynamicFlags dflags0 src_opts
568 checkProcessArgsResult unhandled_flags (basename `joinFileExt` suff)
570 if not (dopt Opt_Cpp dflags) then
571 -- no need to preprocess CPP, just pass input file along
572 -- to the next phase of the pipeline.
573 return (HsPp sf, dflags, maybe_loc, input_fn)
575 output_fn <- get_output_fn (HsPp sf) maybe_loc
576 doCpp dflags True{-raw-} False{-no CC opts-} input_fn output_fn
577 return (HsPp sf, dflags, maybe_loc, output_fn)
579 -------------------------------------------------------------------------------
582 runPhase (HsPp sf) _stop dflags basename suff input_fn get_output_fn maybe_loc
583 = do if not (dopt Opt_Pp dflags) then
584 -- no need to preprocess, just pass input file along
585 -- to the next phase of the pipeline.
586 return (Hsc sf, dflags, maybe_loc, input_fn)
588 let hspp_opts = getOpts dflags opt_F
589 let orig_fn = basename `joinFileExt` suff
590 output_fn <- get_output_fn (Hsc sf) maybe_loc
591 SysTools.runPp dflags
592 ( [ SysTools.Option orig_fn
593 , SysTools.Option input_fn
594 , SysTools.FileOption "" output_fn
596 map SysTools.Option hspp_opts
598 return (Hsc sf, dflags, maybe_loc, output_fn)
600 -----------------------------------------------------------------------------
603 -- Compilation of a single module, in "legacy" mode (_not_ under
604 -- the direction of the compilation manager).
605 runPhase (Hsc src_flavour) stop dflags0 basename suff input_fn get_output_fn _maybe_loc
606 = do -- normal Hsc mode, not mkdependHS
608 -- we add the current directory (i.e. the directory in which
609 -- the .hs files resides) to the import path, since this is
610 -- what gcc does, and it's probably what you want.
611 let current_dir = directoryOf basename
613 paths = includePaths dflags0
614 dflags = dflags0 { includePaths = current_dir : paths }
616 -- gather the imports and module name
617 (hspp_buf,mod_name) <-
619 ExtCoreFile -> do { -- no explicit imports in ExtCore input.
620 ; m <- getCoreModuleName input_fn
621 ; return (Nothing, mkModule m) }
623 other -> do { buf <- hGetStringBuffer input_fn
624 ; (_,_,mod_name) <- getImports dflags buf input_fn
625 ; return (Just buf, mod_name) }
627 -- Build a ModLocation to pass to hscMain.
628 -- The source filename is rather irrelevant by now, but it's used
629 -- by hscMain for messages. hscMain also needs
630 -- the .hi and .o filenames, and this is as good a way
631 -- as any to generate them, and better than most. (e.g. takes
632 -- into accout the -osuf flags)
633 location1 <- mkHomeModLocation2 dflags mod_name basename suff
635 -- Boot-ify it if necessary
636 let location2 | isHsBoot src_flavour = addBootSuffixLocn location1
637 | otherwise = location1
640 -- Take -ohi into account if present
641 -- This can't be done in mkHomeModuleLocation because
642 -- it only applies to the module being compiles
643 let ohi = outputHi dflags
644 location3 | Just fn <- ohi = location2{ ml_hi_file = fn }
645 | otherwise = location2
647 -- Take -o into account if present
648 -- Very like -ohi, but we must *only* do this if we aren't linking
649 -- (If we're linking then the -o applies to the linked thing, not to
650 -- the object file for one module.)
651 -- Note the nasty duplication with the same computation in compileFile above
652 let expl_o_file = outputFile dflags
653 location4 | Just ofile <- expl_o_file
654 , isNoLink (ghcLink dflags)
655 = location3 { ml_obj_file = ofile }
656 | otherwise = location3
658 -- Make the ModSummary to hand to hscMain
659 src_timestamp <- getModificationTime (basename `joinFileExt` suff)
661 unused_field = panic "runPhase:ModSummary field"
662 -- Some fields are not looked at by hscMain
663 mod_summary = ModSummary { ms_mod = mod_name,
664 ms_hsc_src = src_flavour,
665 ms_hspp_file = Just input_fn,
666 ms_hspp_buf = hspp_buf,
667 ms_location = location4,
668 ms_hs_date = src_timestamp,
669 ms_obj_date = Nothing,
670 ms_imps = unused_field,
671 ms_srcimps = unused_field }
673 o_file = ml_obj_file location4 -- The real object file
676 -- Figure out if the source has changed, for recompilation avoidance.
678 -- Setting source_unchanged to True means that M.o seems
679 -- to be up to date wrt M.hs; so no need to recompile unless imports have
680 -- changed (which the compiler itself figures out).
681 -- Setting source_unchanged to False tells the compiler that M.o is out of
682 -- date wrt M.hs (or M.o doesn't exist) so we must recompile regardless.
683 let do_recomp = dopt Opt_RecompChecking dflags
685 if not do_recomp || not (isStopLn stop)
686 -- Set source_unchanged to False unconditionally if
687 -- (a) recompilation checker is off, or
688 -- (b) we aren't going all the way to .o file (e.g. ghc -S)
690 -- Otherwise look at file modification dates
691 else do o_file_exists <- doesFileExist o_file
693 then return False -- Need to recompile
694 else do t2 <- getModificationTime o_file
695 if t2 > src_timestamp
700 let hsc_lang = hscMaybeAdjustTarget dflags stop src_flavour (hscTarget dflags)
701 let next_phase = hscNextPhase dflags src_flavour hsc_lang
702 output_fn <- get_output_fn next_phase (Just location4)
704 let dflags' = dflags { hscTarget = hsc_lang,
705 hscOutName = output_fn,
706 hscStubCOutName = basename ++ "_stub.c",
707 hscStubHOutName = basename ++ "_stub.h",
708 extCoreName = basename ++ ".hcr" }
710 hsc_env <- newHscEnv dflags'
712 -- Tell the finder cache about this module
713 addHomeModuleToFinder hsc_env mod_name location4
716 result <- hscMain hsc_env printErrorsAndWarnings
717 mod_summary source_unchanged
718 False -- No object file
720 Nothing -- No "module i of n" progress info
724 HscFail -> throwDyn (PhaseFailed "hsc" (ExitFailure 1))
726 HscNoRecomp details iface -> do
727 SysTools.touch dflags' "Touching object file" o_file
728 -- The .o file must have a later modification date
729 -- than the source file (else we wouldn't be in HscNoRecomp)
730 -- but we touch it anyway, to keep 'make' happy (we think).
731 return (StopLn, dflags', Just location4, o_file)
733 HscRecomp _details _iface
734 stub_h_exists stub_c_exists
735 _maybe_interpreted_code -> do
738 maybe_stub_o <- compileStub dflags' stub_c_exists
741 Just stub_o -> consIORef v_Ld_inputs stub_o
743 -- In the case of hs-boot files, generate a dummy .o-boot
744 -- stamp file for the benefit of Make
746 HsBootFile -> SysTools.touch dflags' "Touching object file" o_file
749 return (next_phase, dflags', Just location4, output_fn)
751 -----------------------------------------------------------------------------
754 runPhase CmmCpp stop dflags basename suff input_fn get_output_fn maybe_loc
756 output_fn <- get_output_fn Cmm maybe_loc
757 doCpp dflags False{-not raw-} True{-include CC opts-} input_fn output_fn
758 return (Cmm, dflags, maybe_loc, output_fn)
760 runPhase Cmm stop dflags basename suff input_fn get_output_fn maybe_loc
762 let hsc_lang = hscMaybeAdjustTarget dflags stop HsSrcFile (hscTarget dflags)
763 let next_phase = hscNextPhase dflags HsSrcFile hsc_lang
764 output_fn <- get_output_fn next_phase maybe_loc
766 let dflags' = dflags { hscTarget = hsc_lang,
767 hscOutName = output_fn,
768 hscStubCOutName = basename ++ "_stub.c",
769 hscStubHOutName = basename ++ "_stub.h",
770 extCoreName = basename ++ ".hcr" }
772 ok <- hscCmmFile dflags' input_fn
774 when (not ok) $ throwDyn (PhaseFailed "cmm" (ExitFailure 1))
776 return (next_phase, dflags, maybe_loc, output_fn)
778 -----------------------------------------------------------------------------
781 -- we don't support preprocessing .c files (with -E) now. Doing so introduces
782 -- way too many hacks, and I can't say I've ever used it anyway.
784 runPhase cc_phase stop dflags basename suff input_fn get_output_fn maybe_loc
785 | cc_phase `eqPhase` Cc || cc_phase `eqPhase` HCc
786 = do let cc_opts = getOpts dflags opt_c
787 hcc = cc_phase `eqPhase` HCc
789 let cmdline_include_paths = includePaths dflags
791 -- HC files have the dependent packages stamped into them
792 pkgs <- if hcc then getHCFilePackages input_fn else return []
794 -- add package include paths even if we're just compiling .c
795 -- files; this is the Value Add(TM) that using ghc instead of
797 pkg_include_dirs <- getPackageIncludePath dflags pkgs
798 let include_paths = foldr (\ x xs -> "-I" : x : xs) []
799 (cmdline_include_paths ++ pkg_include_dirs)
801 let (md_c_flags, md_regd_c_flags) = machdepCCOpts dflags
802 let pic_c_flags = picCCOpts dflags
804 let verb = getVerbFlag dflags
806 pkg_extra_cc_opts <- getPackageExtraCcOpts dflags pkgs
808 let split_objs = dopt Opt_SplitObjs dflags
809 split_opt | hcc && split_objs = [ "-DUSE_SPLIT_MARKERS" ]
812 let excessPrecision = dopt Opt_ExcessPrecision dflags
816 let mangle = dopt Opt_DoAsmMangling dflags
818 | hcc && mangle = Mangle
820 output_fn <- get_output_fn next_phase maybe_loc
822 SysTools.runCc dflags (
823 -- force the C compiler to interpret this file as C when
824 -- compiling .hc files, by adding the -x c option.
825 -- Also useful for plain .c files, just in case GHC saw a
827 [ SysTools.Option "-x", SysTools.Option "c"] ++
828 [ SysTools.FileOption "" input_fn
829 , SysTools.Option "-o"
830 , SysTools.FileOption "" output_fn
832 ++ map SysTools.Option (
838 ++ [ verb, "-S", "-Wimplicit", "-O" ]
839 ++ [ "-D__GLASGOW_HASKELL__="++cProjectVersionInt ]
842 ++ (if excessPrecision then [] else [ "-ffloat-store" ])
847 return (next_phase, dflags, maybe_loc, output_fn)
849 -- ToDo: postprocess the output from gcc
851 -----------------------------------------------------------------------------
854 runPhase Mangle stop dflags _basename _suff input_fn get_output_fn maybe_loc
855 = do let mangler_opts = getOpts dflags opt_m
858 machdep_opts <- return [ show (stolen_x86_regs dflags) ]
860 machdep_opts <- return []
863 let split = dopt Opt_SplitObjs dflags
865 | split = SplitMangle
867 output_fn <- get_output_fn next_phase maybe_loc
869 SysTools.runMangle dflags (map SysTools.Option mangler_opts
870 ++ [ SysTools.FileOption "" input_fn
871 , SysTools.FileOption "" output_fn
873 ++ map SysTools.Option machdep_opts)
875 return (next_phase, dflags, maybe_loc, output_fn)
877 -----------------------------------------------------------------------------
880 runPhase SplitMangle stop dflags _basename _suff input_fn get_output_fn maybe_loc
881 = do -- tmp_pfx is the prefix used for the split .s files
882 -- We also use it as the file to contain the no. of split .s files (sigh)
883 split_s_prefix <- SysTools.newTempName dflags "split"
884 let n_files_fn = split_s_prefix
886 SysTools.runSplit dflags
887 [ SysTools.FileOption "" input_fn
888 , SysTools.FileOption "" split_s_prefix
889 , SysTools.FileOption "" n_files_fn
892 -- Save the number of split files for future references
893 s <- readFile n_files_fn
894 let n_files = read s :: Int
895 writeIORef v_Split_info (split_s_prefix, n_files)
897 -- Remember to delete all these files
898 addFilesToClean [ split_s_prefix ++ "__" ++ show n ++ ".s"
901 return (SplitAs, dflags, maybe_loc, "**splitmangle**")
902 -- we don't use the filename
904 -----------------------------------------------------------------------------
907 runPhase As stop dflags _basename _suff input_fn get_output_fn maybe_loc
908 = do let as_opts = getOpts dflags opt_a
909 let cmdline_include_paths = includePaths dflags
911 output_fn <- get_output_fn StopLn maybe_loc
913 -- we create directories for the object file, because it
914 -- might be a hierarchical module.
915 createDirectoryHierarchy (directoryOf output_fn)
917 SysTools.runAs dflags
918 (map SysTools.Option as_opts
919 ++ [ SysTools.Option ("-I" ++ p) | p <- cmdline_include_paths ]
920 ++ [ SysTools.Option "-c"
921 , SysTools.FileOption "" input_fn
922 , SysTools.Option "-o"
923 , SysTools.FileOption "" output_fn
926 return (StopLn, dflags, maybe_loc, output_fn)
929 runPhase SplitAs stop dflags basename _suff _input_fn get_output_fn maybe_loc
930 = do let as_opts = getOpts dflags opt_a
932 (split_s_prefix, n) <- readIORef v_Split_info
935 | Just d <- outputDir dflags = d
936 | otherwise = basename ++ "_split"
939 = do let input_s = split_s_prefix ++ "__" ++ show n ++ ".s"
940 let output_o = replaceFilenameDirectory
941 (basename ++ "__" ++ show n ++ ".o")
943 let osuf = objectSuf dflags
944 let real_o = replaceFilenameSuffix output_o osuf
945 SysTools.runAs dflags
946 (map SysTools.Option as_opts ++
947 [ SysTools.Option "-c"
948 , SysTools.Option "-o"
949 , SysTools.FileOption "" real_o
950 , SysTools.FileOption "" input_s
953 mapM_ assemble_file [1..n]
955 output_fn <- get_output_fn StopLn maybe_loc
956 return (StopLn, dflags, maybe_loc, output_fn)
958 -----------------------------------------------------------------------------
959 -- MoveBinary sort-of-phase
960 -- After having produced a binary, move it somewhere else and generate a
961 -- wrapper script calling the binary. Currently, we need this only in
962 -- a parallel way (i.e. in GUM), because PVM expects the binary in a
963 -- central directory.
964 -- This is called from staticLink below, after linking. I haven't made it
965 -- a separate phase to minimise interfering with other modules, and
966 -- we don't need the generality of a phase (MoveBinary is always
967 -- done after linking and makes only sense in a parallel setup) -- HWL
969 runPhase_MoveBinary input_fn
972 pvm_root <- getEnv "PVM_ROOT"
973 pvm_arch <- getEnv "PVM_ARCH"
975 pvm_executable_base = "=" ++ input_fn
976 pvm_executable = pvm_root ++ "/bin/" ++ pvm_arch ++ "/" ++ pvm_executable_base
977 -- nuke old binary; maybe use configur'ed names for cp and rm?
978 system ("rm -f " ++ pvm_executable)
979 -- move the newly created binary into PVM land
980 system ("cp -p " ++ input_fn ++ " " ++ pvm_executable)
981 -- generate a wrapper script for running a parallel prg under PVM
982 writeFile input_fn (mk_pvm_wrapper_script pvm_executable pvm_executable_base sysMan)
985 -- generates a Perl skript starting a parallel prg under PVM
986 mk_pvm_wrapper_script :: String -> String -> String -> String
987 mk_pvm_wrapper_script pvm_executable pvm_executable_base sysMan = unlines $
989 "eval 'exec perl -S $0 ${1+\"$@\"}'",
990 " if $running_under_some_shell;",
991 "# =!=!=!=!=!=!=!=!=!=!=!",
992 "# This script is automatically generated: DO NOT EDIT!!!",
993 "# Generated by Glasgow Haskell Compiler",
994 "# ngoqvam choHbogh vaj' vIHoHnISbej !!!!",
996 "$pvm_executable = '" ++ pvm_executable ++ "';",
997 "$pvm_executable_base = '" ++ pvm_executable_base ++ "';",
998 "$SysMan = '" ++ sysMan ++ "';",
1000 {- ToDo: add the magical shortcuts again iff we actually use them -- HWL
1001 "# first, some magical shortcuts to run "commands" on the binary",
1002 "# (which is hidden)",
1003 "if ($#ARGV == 1 && $ARGV[0] eq '+RTS' && $ARGV[1] =~ /^--((size|file|strip|rm|nm).*)/ ) {",
1004 " local($cmd) = $1;",
1005 " system("$cmd $pvm_executable");",
1006 " exit(0); # all done",
1009 "# Now, run the real binary; process the args first",
1010 "$ENV{'PE'} = $pvm_executable_base;", -- ++ pvm_executable_base,
1012 "$nprocessors = 0; # the default: as many PEs as machines in PVM config",
1013 "@nonPVM_args = ();",
1014 "$in_RTS_args = 0;",
1016 "args: while ($a = shift(@ARGV)) {",
1017 " if ( $a eq '+RTS' ) {",
1018 " $in_RTS_args = 1;",
1019 " } elsif ( $a eq '-RTS' ) {",
1020 " $in_RTS_args = 0;",
1022 " if ( $a eq '-d' && $in_RTS_args ) {",
1024 " } elsif ( $a =~ /^-qN(\\d+)/ && $in_RTS_args ) {",
1025 " $nprocessors = $1;",
1026 " } elsif ( $a =~ /^-qp(\\d+)/ && $in_RTS_args ) {",
1027 " $nprocessors = $1;",
1029 " push(@nonPVM_args, $a);",
1033 "local($return_val) = 0;",
1034 "# Start the parallel execution by calling SysMan",
1035 "system(\"$SysMan $debug $pvm_executable $nprocessors @nonPVM_args\");",
1036 "$return_val = $?;",
1037 "# ToDo: fix race condition moving files and flushing them!!",
1038 "system(\"cp $ENV{'HOME'}/$pvm_executable_base.???.gr .\") if -f \"$ENV{'HOME'}/$pvm_executable_base.002.gr\";",
1039 "exit($return_val);"
1042 -----------------------------------------------------------------------------
1043 -- Complain about non-dynamic flags in OPTIONS pragmas
1045 checkProcessArgsResult flags filename
1046 = do when (notNull flags) (throwDyn (ProgramError (
1047 showSDoc (hang (text filename <> char ':')
1048 4 (text "unknown flags in {-# OPTIONS #-} pragma:" <+>
1049 hsep (map text flags)))
1052 -----------------------------------------------------------------------------
1053 -- Look for the /* GHC_PACKAGES ... */ comment at the top of a .hc file
1055 getHCFilePackages :: FilePath -> IO [PackageId]
1056 getHCFilePackages filename =
1057 EXCEPTION.bracket (openFile filename ReadMode) hClose $ \h -> do
1060 '/':'*':' ':'G':'H':'C':'_':'P':'A':'C':'K':'A':'G':'E':'S':rest ->
1061 return (map stringToPackageId (words rest))
1065 -----------------------------------------------------------------------------
1066 -- Static linking, of .o files
1068 -- The list of packages passed to link is the list of packages on
1069 -- which this program depends, as discovered by the compilation
1070 -- manager. It is combined with the list of packages that the user
1071 -- specifies on the command line with -package flags.
1073 -- In one-shot linking mode, we can't discover the package
1074 -- dependencies (because we haven't actually done any compilation or
1075 -- read any interface files), so the user must explicitly specify all
1078 staticLink :: DynFlags -> [FilePath] -> [PackageId] -> IO ()
1079 staticLink dflags o_files dep_packages = do
1080 let verb = getVerbFlag dflags
1082 -- get the full list of packages to link with, by combining the
1083 -- explicit packages with the auto packages and all of their
1084 -- dependencies, and eliminating duplicates.
1086 let o_file = outputFile dflags
1087 #if defined(mingw32_HOST_OS)
1088 let output_fn = case o_file of { Just s -> s; Nothing -> "main.exe"; }
1090 let output_fn = case o_file of { Just s -> s; Nothing -> "a.out"; }
1093 pkg_lib_paths <- getPackageLibraryPath dflags dep_packages
1094 let pkg_lib_path_opts = map ("-L"++) pkg_lib_paths
1096 let lib_paths = libraryPaths dflags
1097 let lib_path_opts = map ("-L"++) lib_paths
1099 pkg_link_opts <- getPackageLinkOpts dflags dep_packages
1101 #ifdef darwin_TARGET_OS
1102 pkg_framework_paths <- getPackageFrameworkPath dflags dep_packages
1103 let pkg_framework_path_opts = map ("-F"++) pkg_framework_paths
1105 let framework_paths = frameworkPaths dflags
1106 framework_path_opts = map ("-F"++) framework_paths
1108 pkg_frameworks <- getPackageFrameworks dflags dep_packages
1109 let pkg_framework_opts = concat [ ["-framework", fw] | fw <- pkg_frameworks ]
1111 let frameworks = cmdlineFrameworks dflags
1112 framework_opts = concat [ ["-framework", fw] | fw <- reverse frameworks ]
1113 -- reverse because they're added in reverse order from the cmd line
1116 -- probably _stub.o files
1117 extra_ld_inputs <- readIORef v_Ld_inputs
1119 -- opts from -optl-<blah> (including -l<blah> options)
1120 let extra_ld_opts = getOpts dflags opt_l
1122 let ways = wayNames dflags
1124 -- Here are some libs that need to be linked at the *end* of
1125 -- the command line, because they contain symbols that are referred to
1126 -- by the RTS. We can't therefore use the ordinary way opts for these.
1128 debug_opts | WayDebug `elem` ways = [
1129 #if defined(HAVE_LIBBFD)
1136 thread_opts | WayThreaded `elem` ways = [
1137 #if !defined(mingw32_TARGET_OS) && !defined(freebsd_TARGET_OS)
1140 #if defined(osf3_TARGET_OS)
1146 let (md_c_flags, _) = machdepCCOpts dflags
1147 SysTools.runLink dflags (
1148 [ SysTools.Option verb
1149 , SysTools.Option "-o"
1150 , SysTools.FileOption "" output_fn
1152 ++ map SysTools.Option (
1158 #ifdef darwin_TARGET_OS
1159 ++ framework_path_opts
1162 ++ pkg_lib_path_opts
1164 #ifdef darwin_TARGET_OS
1165 ++ pkg_framework_path_opts
1166 ++ pkg_framework_opts
1172 -- parallel only: move binary to another dir -- HWL
1173 when (WayPar `elem` ways)
1174 (do success <- runPhase_MoveBinary output_fn
1175 if success then return ()
1176 else throwDyn (InstallationError ("cannot move binary to PVM dir")))
1178 -----------------------------------------------------------------------------
1179 -- Making a DLL (only for Win32)
1181 doMkDLL :: DynFlags -> [String] -> [PackageId] -> IO ()
1182 doMkDLL dflags o_files dep_packages = do
1183 let verb = getVerbFlag dflags
1184 let static = opt_Static
1185 let no_hs_main = dopt Opt_NoHsMain dflags
1186 let o_file = outputFile dflags
1187 let output_fn = case o_file of { Just s -> s; Nothing -> "HSdll.dll"; }
1189 pkg_lib_paths <- getPackageLibraryPath dflags dep_packages
1190 let pkg_lib_path_opts = map ("-L"++) pkg_lib_paths
1192 let lib_paths = libraryPaths dflags
1193 let lib_path_opts = map ("-L"++) lib_paths
1195 pkg_link_opts <- getPackageLinkOpts dflags dep_packages
1197 -- probably _stub.o files
1198 extra_ld_inputs <- readIORef v_Ld_inputs
1200 -- opts from -optdll-<blah>
1201 let extra_ld_opts = getOpts dflags opt_dll
1203 let pstate = pkgState dflags
1204 rts_id | ExtPackage id <- rtsPackageId pstate = id
1205 | otherwise = panic "staticLink: rts package missing"
1206 base_id | ExtPackage id <- basePackageId pstate = id
1207 | otherwise = panic "staticLink: base package missing"
1208 rts_pkg = getPackageDetails pstate rts_id
1209 base_pkg = getPackageDetails pstate base_id
1211 let extra_os = if static || no_hs_main
1213 else [ head (libraryDirs rts_pkg) ++ "/Main.dll_o",
1214 head (libraryDirs base_pkg) ++ "/PrelMain.dll_o" ]
1216 let (md_c_flags, _) = machdepCCOpts dflags
1217 SysTools.runMkDLL dflags
1218 ([ SysTools.Option verb
1219 , SysTools.Option "-o"
1220 , SysTools.FileOption "" output_fn
1222 ++ map SysTools.Option (
1226 ++ [ "--target=i386-mingw32" ]
1230 ++ pkg_lib_path_opts
1232 ++ (if "--def" `elem` (concatMap words extra_ld_opts)
1234 else [ "--export-all" ])
1237 -- -----------------------------------------------------------------------------
1240 doCpp :: DynFlags -> Bool -> Bool -> FilePath -> FilePath -> IO ()
1241 doCpp dflags raw include_cc_opts input_fn output_fn = do
1242 let hscpp_opts = getOpts dflags opt_P
1243 let cmdline_include_paths = includePaths dflags
1245 pkg_include_dirs <- getPackageIncludePath dflags []
1246 let include_paths = foldr (\ x xs -> "-I" : x : xs) []
1247 (cmdline_include_paths ++ pkg_include_dirs)
1249 let verb = getVerbFlag dflags
1252 | not include_cc_opts = []
1253 | otherwise = (optc ++ md_c_flags)
1255 optc = getOpts dflags opt_c
1256 (md_c_flags, _) = machdepCCOpts dflags
1258 let cpp_prog args | raw = SysTools.runCpp dflags args
1259 | otherwise = SysTools.runCc dflags (SysTools.Option "-E" : args)
1262 [ "-D" ++ HOST_OS ++ "_BUILD_OS=1",
1263 "-D" ++ HOST_ARCH ++ "_BUILD_ARCH=1",
1264 "-D" ++ TARGET_OS ++ "_HOST_OS=1",
1265 "-D" ++ TARGET_ARCH ++ "_HOST_ARCH=1" ]
1266 -- remember, in code we *compile*, the HOST is the same our TARGET,
1267 -- and BUILD is the same as our HOST.
1269 cpp_prog ([SysTools.Option verb]
1270 ++ map SysTools.Option include_paths
1271 ++ map SysTools.Option hsSourceCppOpts
1272 ++ map SysTools.Option hscpp_opts
1273 ++ map SysTools.Option cc_opts
1274 ++ map SysTools.Option target_defs
1275 ++ [ SysTools.Option "-x"
1276 , SysTools.Option "c"
1277 , SysTools.Option input_fn
1278 -- We hackily use Option instead of FileOption here, so that the file
1279 -- name is not back-slashed on Windows. cpp is capable of
1280 -- dealing with / in filenames, so it works fine. Furthermore
1281 -- if we put in backslashes, cpp outputs #line directives
1282 -- with *double* backslashes. And that in turn means that
1283 -- our error messages get double backslashes in them.
1284 -- In due course we should arrange that the lexer deals
1285 -- with these \\ escapes properly.
1286 , SysTools.Option "-o"
1287 , SysTools.FileOption "" output_fn
1290 cHaskell1Version = "5" -- i.e., Haskell 98
1292 -- Default CPP defines in Haskell source
1294 [ "-D__HASKELL1__="++cHaskell1Version
1295 , "-D__GLASGOW_HASKELL__="++cProjectVersionInt
1297 , "-D__CONCURRENT_HASKELL__"
1300 -----------------------------------------------------------------------------
1301 -- Reading OPTIONS pragmas
1303 getOptionsFromSource
1304 :: String -- input file
1305 -> IO [String] -- options, if any
1306 getOptionsFromSource file
1307 = do h <- openFile file ReadMode
1308 look h `finally` hClose h
1311 r <- tryJust ioErrors (hGetLine h)
1313 Left e | isEOFError e -> return []
1314 | otherwise -> ioError e
1316 let l = removeSpaces l'
1318 () | null l -> look h
1319 | prefixMatch "#" l -> look h
1320 | prefixMatch "{-# LINE" l -> look h -- -}
1321 | Just opts <- matchOptions l
1322 -> do rest <- look h
1323 return (opts ++ rest)
1324 | otherwise -> return []
1326 getOptionsFromStringBuffer :: StringBuffer -> [(Int,String)]
1327 getOptionsFromStringBuffer buffer@(StringBuffer _ len# _) =
1329 ls = lines (lexemeToString buffer (I# len#)) -- lazy, so it's ok
1335 let l = removeSpaces l'
1337 () | null l -> look (i+1) ls
1338 | prefixMatch "#" l -> look (i+1) ls
1339 | prefixMatch "{-# LINE" l -> look (i+1) ls -- -}
1340 | Just opts <- matchOptions l
1341 -> zip (repeat i) opts ++ look (i+1) ls
1344 -- detect {-# OPTIONS_GHC ... #-}. For the time being, we accept OPTIONS
1345 -- instead of OPTIONS_GHC, but that is deprecated.
1347 | Just s1 <- maybePrefixMatch "{-#" s -- -}
1348 = matchOptions1 (removeSpaces s1)
1353 | Just s2 <- maybePrefixMatch "OPTIONS" s
1355 _ | Just s3 <- maybePrefixMatch "_GHC" s2, not (is_ident (head s3))
1357 | not (is_ident (head s2))
1360 -> Just [] -- OPTIONS_anything is ignored, not treated as start of source
1361 | Just s2 <- maybePrefixMatch "INCLUDE" s, not (is_ident (head s2)),
1362 Just s3 <- maybePrefixMatch "}-#" (reverse s2)
1363 = Just ["-#include", removeSpaces (reverse s3)]
1364 | otherwise = Nothing
1366 | Just s3 <- maybePrefixMatch "}-#" (reverse s) = Just (words (reverse s3))
1367 | otherwise = Nothing
1370 optionsErrorMsgs :: [String] -> [(Int,String)] -> FilePath -> Messages
1371 optionsErrorMsgs unhandled_flags flags_lines filename
1372 = (emptyBag, listToBag (map mkMsg unhandled_flags_lines))
1374 unhandled_flags_lines = [ (l,f) | f <- unhandled_flags,
1375 (l,f') <- flags_lines, f == f' ]
1377 ErrUtils.mkPlainErrMsg (srcLocSpan loc) $
1378 text "unknown flag in {-# OPTIONS #-} pragma:" <+> text flag
1380 loc = mkSrcLoc (mkFastString filename) line 0
1381 -- ToDo: we need a better SrcSpan here
1383 -- -----------------------------------------------------------------------------
1386 hscNextPhase :: DynFlags -> HscSource -> HscTarget -> Phase
1387 hscNextPhase dflags HsBootFile hsc_lang = StopLn
1388 hscNextPhase dflags other hsc_lang =
1391 HscAsm | dopt Opt_SplitObjs dflags -> SplitMangle
1393 HscNothing -> StopLn
1394 HscInterpreted -> StopLn
1398 hscMaybeAdjustTarget :: DynFlags -> Phase -> HscSource -> HscTarget -> HscTarget
1399 hscMaybeAdjustTarget dflags stop HsBootFile current_hsc_lang
1400 = HscNothing -- No output (other than Foo.hi-boot) for hs-boot files
1401 hscMaybeAdjustTarget dflags stop other current_hsc_lang
1404 keep_hc = dopt Opt_KeepHcFiles dflags
1406 -- don't change the lang if we're interpreting
1407 | current_hsc_lang == HscInterpreted = current_hsc_lang
1409 -- force -fvia-C if we are being asked for a .hc file
1410 | HCc <- stop = HscC
1412 -- otherwise, stick to the plan
1413 | otherwise = current_hsc_lang
1415 GLOBAL_VAR(v_Split_info, ("",0), (String,Int))
1416 -- The split prefix and number of files