PageRenderTime 59ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/ghc-7.0.4/compiler/main/DriverPipeline.hs

http://picorec.googlecode.com/
Haskell | 1577 lines | 988 code | 244 blank | 345 comment | 64 complexity | b5691a045630b004fbbafdb07f3ba100 MD5 | raw file
Possible License(s): BSD-3-Clause, BSD-2-Clause

Large files files are truncated, but you can click here to view the full file

  1. {-# OPTIONS -fno-cse #-}
  2. -- -fno-cse is needed for GLOBAL_VAR's to behave properly
  3. -----------------------------------------------------------------------------
  4. --
  5. -- GHC Driver
  6. --
  7. -- (c) The University of Glasgow 2005
  8. --
  9. -----------------------------------------------------------------------------
  10. module DriverPipeline (
  11. -- Run a series of compilation steps in a pipeline, for a
  12. -- collection of source files.
  13. oneShot, compileFile,
  14. -- Interfaces for the batch-mode driver
  15. linkBinary,
  16. -- Interfaces for the compilation manager (interpreted/batch-mode)
  17. preprocess,
  18. compile, compile',
  19. link,
  20. ) where
  21. #include "HsVersions.h"
  22. import Packages
  23. import HeaderInfo
  24. import DriverPhases
  25. import SysTools
  26. import HscMain
  27. import Finder
  28. import HscTypes
  29. import Outputable
  30. import Module
  31. import UniqFM ( eltsUFM )
  32. import ErrUtils
  33. import DynFlags
  34. import StaticFlags ( v_Ld_inputs, opt_PIC, opt_Static, WayName(..) )
  35. import Config
  36. import Panic
  37. import Util
  38. import StringBuffer ( hGetStringBuffer )
  39. import BasicTypes ( SuccessFlag(..) )
  40. import Maybes ( expectJust )
  41. import ParserCoreUtils ( getCoreModuleName )
  42. import SrcLoc
  43. import FastString
  44. import LlvmCodeGen ( llvmFixupAsm )
  45. -- import MonadUtils
  46. -- import Data.Either
  47. import Exception
  48. import Data.IORef ( readIORef )
  49. -- import GHC.Exts ( Int(..) )
  50. import System.Directory
  51. import System.FilePath
  52. import System.IO
  53. import System.IO.Error as IO
  54. import Control.Monad
  55. import Data.List ( isSuffixOf )
  56. import Data.Maybe
  57. import System.Environment
  58. -- ---------------------------------------------------------------------------
  59. -- Pre-process
  60. -- | Just preprocess a file, put the result in a temp. file (used by the
  61. -- compilation manager during the summary phase).
  62. --
  63. -- We return the augmented DynFlags, because they contain the result
  64. -- of slurping in the OPTIONS pragmas
  65. preprocess :: GhcMonad m =>
  66. HscEnv
  67. -> (FilePath, Maybe Phase) -- ^ filename and starting phase
  68. -> m (DynFlags, FilePath)
  69. preprocess hsc_env (filename, mb_phase) =
  70. ASSERT2(isJust mb_phase || isHaskellSrcFilename filename, text filename)
  71. runPipeline anyHsc hsc_env (filename, mb_phase)
  72. Nothing Temporary Nothing{-no ModLocation-}
  73. -- ---------------------------------------------------------------------------
  74. -- | Compile
  75. --
  76. -- Compile a single module, under the control of the compilation manager.
  77. --
  78. -- This is the interface between the compilation manager and the
  79. -- compiler proper (hsc), where we deal with tedious details like
  80. -- reading the OPTIONS pragma from the source file, and passing the
  81. -- output of hsc through the C compiler.
  82. --
  83. -- NB. No old interface can also mean that the source has changed.
  84. compile :: GhcMonad m =>
  85. HscEnv
  86. -> ModSummary -- ^ summary for module being compiled
  87. -> Int -- ^ module N ...
  88. -> Int -- ^ ... of M
  89. -> Maybe ModIface -- ^ old interface, if we have one
  90. -> Maybe Linkable -- ^ old linkable, if we have one
  91. -> m HomeModInfo -- ^ the complete HomeModInfo, if successful
  92. compile = compile' (hscCompileNothing, hscCompileInteractive, hscCompileBatch)
  93. type Compiler m a = HscEnv -> ModSummary -> Bool
  94. -> Maybe ModIface -> Maybe (Int, Int)
  95. -> m a
  96. compile' :: GhcMonad m =>
  97. (Compiler m (HscStatus, ModIface, ModDetails),
  98. Compiler m (InteractiveStatus, ModIface, ModDetails),
  99. Compiler m (HscStatus, ModIface, ModDetails))
  100. -> HscEnv
  101. -> ModSummary -- ^ summary for module being compiled
  102. -> Int -- ^ module N ...
  103. -> Int -- ^ ... of M
  104. -> Maybe ModIface -- ^ old interface, if we have one
  105. -> Maybe Linkable -- ^ old linkable, if we have one
  106. -> m HomeModInfo -- ^ the complete HomeModInfo, if successful
  107. compile' (nothingCompiler, interactiveCompiler, batchCompiler)
  108. hsc_env0 summary mod_index nmods mb_old_iface maybe_old_linkable
  109. = do
  110. let dflags0 = ms_hspp_opts summary
  111. this_mod = ms_mod summary
  112. src_flavour = ms_hsc_src summary
  113. location = ms_location summary
  114. input_fn = expectJust "compile:hs" (ml_hs_file location)
  115. input_fnpp = ms_hspp_file summary
  116. liftIO $ debugTraceMsg dflags0 2 (text "compile: input file" <+> text input_fnpp)
  117. let basename = dropExtension input_fn
  118. -- We add the directory in which the .hs files resides) to the import path.
  119. -- This is needed when we try to compile the .hc file later, if it
  120. -- imports a _stub.h file that we created here.
  121. let current_dir = case takeDirectory basename of
  122. "" -> "." -- XXX Hack
  123. d -> d
  124. old_paths = includePaths dflags0
  125. dflags = dflags0 { includePaths = current_dir : old_paths }
  126. hsc_env = hsc_env0 {hsc_dflags = dflags}
  127. -- Figure out what lang we're generating
  128. let hsc_lang = hscMaybeAdjustTarget dflags StopLn src_flavour (hscTarget dflags)
  129. -- ... and what the next phase should be
  130. let next_phase = hscNextPhase dflags src_flavour hsc_lang
  131. -- ... and what file to generate the output into
  132. output_fn <- liftIO $ getOutputFilename next_phase
  133. Temporary basename dflags next_phase (Just location)
  134. let dflags' = dflags { hscTarget = hsc_lang,
  135. hscOutName = output_fn,
  136. extCoreName = basename ++ ".hcr" }
  137. let hsc_env' = hsc_env { hsc_dflags = dflags' }
  138. -- -fforce-recomp should also work with --make
  139. let force_recomp = dopt Opt_ForceRecomp dflags
  140. source_unchanged = isJust maybe_old_linkable && not force_recomp
  141. object_filename = ml_obj_file location
  142. let getStubLinkable False = return []
  143. getStubLinkable True
  144. = do stub_o <- compileStub hsc_env' this_mod location
  145. return [ DotO stub_o ]
  146. handleBatch HscNoRecomp
  147. = ASSERT (isJust maybe_old_linkable)
  148. return maybe_old_linkable
  149. handleBatch (HscRecomp hasStub _)
  150. | isHsBoot src_flavour
  151. = do when (isObjectTarget hsc_lang) $ -- interpreted reaches here too
  152. liftIO $ SysTools.touch dflags' "Touching object file"
  153. object_filename
  154. return maybe_old_linkable
  155. | otherwise
  156. = do stub_unlinked <- getStubLinkable hasStub
  157. (hs_unlinked, unlinked_time) <-
  158. case hsc_lang of
  159. HscNothing
  160. -> return ([], ms_hs_date summary)
  161. -- We're in --make mode: finish the compilation pipeline.
  162. _other
  163. -> do _ <- runPipeline StopLn hsc_env' (output_fn,Nothing)
  164. (Just basename)
  165. Persistent
  166. (Just location)
  167. -- The object filename comes from the ModLocation
  168. o_time <- liftIO $ getModificationTime object_filename
  169. return ([DotO object_filename], o_time)
  170. let linkable = LM unlinked_time this_mod
  171. (hs_unlinked ++ stub_unlinked)
  172. return (Just linkable)
  173. handleInterpreted HscNoRecomp
  174. = ASSERT (isJust maybe_old_linkable)
  175. return maybe_old_linkable
  176. handleInterpreted (HscRecomp _hasStub Nothing)
  177. = ASSERT (isHsBoot src_flavour)
  178. return maybe_old_linkable
  179. handleInterpreted (HscRecomp hasStub (Just (comp_bc, modBreaks)))
  180. = do stub_unlinked <- getStubLinkable hasStub
  181. let hs_unlinked = [BCOs comp_bc modBreaks]
  182. unlinked_time = ms_hs_date summary
  183. -- Why do we use the timestamp of the source file here,
  184. -- rather than the current time? This works better in
  185. -- the case where the local clock is out of sync
  186. -- with the filesystem's clock. It's just as accurate:
  187. -- if the source is modified, then the linkable will
  188. -- be out of date.
  189. let linkable = LM unlinked_time this_mod
  190. (hs_unlinked ++ stub_unlinked)
  191. return (Just linkable)
  192. let -- runCompiler :: Compiler result -> (result -> Maybe Linkable)
  193. -- -> m HomeModInfo
  194. runCompiler compiler handle
  195. = do (result, iface, details)
  196. <- compiler hsc_env' summary source_unchanged mb_old_iface
  197. (Just (mod_index, nmods))
  198. linkable <- handle result
  199. return (HomeModInfo{ hm_details = details,
  200. hm_iface = iface,
  201. hm_linkable = linkable })
  202. -- run the compiler
  203. case hsc_lang of
  204. HscInterpreted ->
  205. runCompiler interactiveCompiler handleInterpreted
  206. HscNothing ->
  207. runCompiler nothingCompiler handleBatch
  208. _other ->
  209. runCompiler batchCompiler handleBatch
  210. -----------------------------------------------------------------------------
  211. -- stub .h and .c files (for foreign export support)
  212. -- The _stub.c file is derived from the haskell source file, possibly taking
  213. -- into account the -stubdir option.
  214. --
  215. -- Consequently, we derive the _stub.o filename from the haskell object
  216. -- filename.
  217. --
  218. -- This isn't necessarily the same as the object filename we
  219. -- would get if we just compiled the _stub.c file using the pipeline.
  220. -- For example:
  221. --
  222. -- ghc src/A.hs -odir obj
  223. --
  224. -- results in obj/A.o, and src/A_stub.c. If we compile src/A_stub.c with
  225. -- -odir obj, we would get obj/src/A_stub.o, which is wrong; we want
  226. -- obj/A_stub.o.
  227. compileStub :: GhcMonad m => HscEnv -> Module -> ModLocation
  228. -> m FilePath
  229. compileStub hsc_env mod location = do
  230. -- compile the _stub.c file w/ gcc
  231. let (stub_c,_,stub_o) = mkStubPaths (hsc_dflags hsc_env)
  232. (moduleName mod) location
  233. _ <- runPipeline StopLn hsc_env (stub_c,Nothing) Nothing
  234. (SpecificFile stub_o) Nothing{-no ModLocation-}
  235. return stub_o
  236. -- ---------------------------------------------------------------------------
  237. -- Link
  238. link :: GhcLink -- interactive or batch
  239. -> DynFlags -- dynamic flags
  240. -> Bool -- attempt linking in batch mode?
  241. -> HomePackageTable -- what to link
  242. -> IO SuccessFlag
  243. -- For the moment, in the batch linker, we don't bother to tell doLink
  244. -- which packages to link -- it just tries all that are available.
  245. -- batch_attempt_linking should only be *looked at* in batch mode. It
  246. -- should only be True if the upsweep was successful and someone
  247. -- exports main, i.e., we have good reason to believe that linking
  248. -- will succeed.
  249. #ifdef GHCI
  250. link LinkInMemory _ _ _
  251. = do -- Not Linking...(demand linker will do the job)
  252. return Succeeded
  253. #endif
  254. link NoLink _ _ _
  255. = return Succeeded
  256. link LinkBinary dflags batch_attempt_linking hpt
  257. = link' dflags batch_attempt_linking hpt
  258. link LinkDynLib dflags batch_attempt_linking hpt
  259. = link' dflags batch_attempt_linking hpt
  260. #ifndef GHCI
  261. -- warning suppression
  262. link other _ _ _ = panicBadLink other
  263. #endif
  264. panicBadLink :: GhcLink -> a
  265. panicBadLink other = panic ("link: GHC not built to link this way: " ++
  266. show other)
  267. link' :: DynFlags -- dynamic flags
  268. -> Bool -- attempt linking in batch mode?
  269. -> HomePackageTable -- what to link
  270. -> IO SuccessFlag
  271. link' dflags batch_attempt_linking hpt
  272. | batch_attempt_linking
  273. = do
  274. let
  275. home_mod_infos = eltsUFM hpt
  276. -- the packages we depend on
  277. pkg_deps = concatMap (dep_pkgs . mi_deps . hm_iface) home_mod_infos
  278. -- the linkables to link
  279. linkables = map (expectJust "link".hm_linkable) home_mod_infos
  280. debugTraceMsg dflags 3 (text "link: linkables are ..." $$ vcat (map ppr linkables))
  281. -- check for the -no-link flag
  282. if isNoLink (ghcLink dflags)
  283. then do debugTraceMsg dflags 3 (text "link(batch): linking omitted (-c flag given).")
  284. return Succeeded
  285. else do
  286. let getOfiles (LM _ _ us) = map nameOfObject (filter isObject us)
  287. obj_files = concatMap getOfiles linkables
  288. exe_file = exeFileName dflags
  289. linking_needed <- linkingNeeded dflags linkables pkg_deps
  290. if not (dopt Opt_ForceRecomp dflags) && not linking_needed
  291. then do debugTraceMsg dflags 2 (text exe_file <+> ptext (sLit "is up to date, linking not required."))
  292. return Succeeded
  293. else do
  294. debugTraceMsg dflags 1 (ptext (sLit "Linking") <+> text exe_file
  295. <+> text "...")
  296. -- Don't showPass in Batch mode; doLink will do that for us.
  297. let link = case ghcLink dflags of
  298. LinkBinary -> linkBinary
  299. LinkDynLib -> linkDynLib
  300. other -> panicBadLink other
  301. link dflags obj_files pkg_deps
  302. debugTraceMsg dflags 3 (text "link: done")
  303. -- linkBinary only returns if it succeeds
  304. return Succeeded
  305. | otherwise
  306. = do debugTraceMsg dflags 3 (text "link(batch): upsweep (partially) failed OR" $$
  307. text " Main.main not exported; not linking.")
  308. return Succeeded
  309. linkingNeeded :: DynFlags -> [Linkable] -> [PackageId] -> IO Bool
  310. linkingNeeded dflags linkables pkg_deps = do
  311. -- if the modification time on the executable is later than the
  312. -- modification times on all of the objects and libraries, then omit
  313. -- linking (unless the -fforce-recomp flag was given).
  314. let exe_file = exeFileName dflags
  315. e_exe_time <- IO.try $ getModificationTime exe_file
  316. case e_exe_time of
  317. Left _ -> return True
  318. Right t -> do
  319. -- first check object files and extra_ld_inputs
  320. extra_ld_inputs <- readIORef v_Ld_inputs
  321. e_extra_times <- mapM (IO.try . getModificationTime) extra_ld_inputs
  322. let (errs,extra_times) = splitEithers e_extra_times
  323. let obj_times = map linkableTime linkables ++ extra_times
  324. if not (null errs) || any (t <) obj_times
  325. then return True
  326. else do
  327. -- next, check libraries. XXX this only checks Haskell libraries,
  328. -- not extra_libraries or -l things from the command line.
  329. let pkg_map = pkgIdMap (pkgState dflags)
  330. pkg_hslibs = [ (libraryDirs c, lib)
  331. | Just c <- map (lookupPackage pkg_map) pkg_deps,
  332. lib <- packageHsLibs dflags c ]
  333. pkg_libfiles <- mapM (uncurry findHSLib) pkg_hslibs
  334. if any isNothing pkg_libfiles then return True else do
  335. e_lib_times <- mapM (IO.try . getModificationTime)
  336. (catMaybes pkg_libfiles)
  337. let (lib_errs,lib_times) = splitEithers e_lib_times
  338. if not (null lib_errs) || any (t <) lib_times
  339. then return True
  340. else return False
  341. findHSLib :: [String] -> String -> IO (Maybe FilePath)
  342. findHSLib dirs lib = do
  343. let batch_lib_file = "lib" ++ lib <.> "a"
  344. found <- filterM doesFileExist (map (</> batch_lib_file) dirs)
  345. case found of
  346. [] -> return Nothing
  347. (x:_) -> return (Just x)
  348. -- -----------------------------------------------------------------------------
  349. -- Compile files in one-shot mode.
  350. oneShot :: GhcMonad m =>
  351. HscEnv -> Phase -> [(String, Maybe Phase)] -> m ()
  352. oneShot hsc_env stop_phase srcs = do
  353. o_files <- mapM (compileFile hsc_env stop_phase) srcs
  354. liftIO $ doLink (hsc_dflags hsc_env) stop_phase o_files
  355. compileFile :: GhcMonad m =>
  356. HscEnv -> Phase -> (FilePath, Maybe Phase) -> m FilePath
  357. compileFile hsc_env stop_phase (src, mb_phase) = do
  358. exists <- liftIO $ doesFileExist src
  359. when (not exists) $
  360. ghcError (CmdLineError ("does not exist: " ++ src))
  361. let
  362. dflags = hsc_dflags hsc_env
  363. split = dopt Opt_SplitObjs dflags
  364. mb_o_file = outputFile dflags
  365. ghc_link = ghcLink dflags -- Set by -c or -no-link
  366. -- When linking, the -o argument refers to the linker's output.
  367. -- otherwise, we use it as the name for the pipeline's output.
  368. output
  369. | StopLn <- stop_phase, not (isNoLink ghc_link) = Persistent
  370. -- -o foo applies to linker
  371. | Just o_file <- mb_o_file = SpecificFile o_file
  372. -- -o foo applies to the file we are compiling now
  373. | otherwise = Persistent
  374. stop_phase' = case stop_phase of
  375. As | split -> SplitAs
  376. _ -> stop_phase
  377. ( _, out_file) <- runPipeline stop_phase' hsc_env
  378. (src, mb_phase) Nothing output
  379. Nothing{-no ModLocation-}
  380. return out_file
  381. doLink :: DynFlags -> Phase -> [FilePath] -> IO ()
  382. doLink dflags stop_phase o_files
  383. | not (isStopLn stop_phase)
  384. = return () -- We stopped before the linking phase
  385. | otherwise
  386. = case ghcLink dflags of
  387. NoLink -> return ()
  388. LinkBinary -> linkBinary dflags o_files []
  389. LinkDynLib -> linkDynLib dflags o_files []
  390. other -> panicBadLink other
  391. -- ---------------------------------------------------------------------------
  392. data PipelineOutput
  393. = Temporary
  394. -- ^ Output should be to a temporary file: we're going to
  395. -- run more compilation steps on this output later.
  396. | Persistent
  397. -- ^ We want a persistent file, i.e. a file in the current directory
  398. -- derived from the input filename, but with the appropriate extension.
  399. -- eg. in "ghc -c Foo.hs" the output goes into ./Foo.o.
  400. | SpecificFile FilePath
  401. -- ^ The output must go into the specified file.
  402. -- | Run a compilation pipeline, consisting of multiple phases.
  403. --
  404. -- This is the interface to the compilation pipeline, which runs
  405. -- a series of compilation steps on a single source file, specifying
  406. -- at which stage to stop.
  407. --
  408. -- The DynFlags can be modified by phases in the pipeline (eg. by
  409. -- OPTIONS_GHC pragmas), and the changes affect later phases in the
  410. -- pipeline.
  411. runPipeline
  412. :: GhcMonad m =>
  413. Phase -- ^ When to stop
  414. -> HscEnv -- ^ Compilation environment
  415. -> (FilePath,Maybe Phase) -- ^ Input filename (and maybe -x suffix)
  416. -> Maybe FilePath -- ^ original basename (if different from ^^^)
  417. -> PipelineOutput -- ^ Output filename
  418. -> Maybe ModLocation -- ^ A ModLocation, if this is a Haskell module
  419. -> m (DynFlags, FilePath) -- ^ (final flags, output filename)
  420. runPipeline stop_phase hsc_env0 (input_fn, mb_phase) mb_basename output maybe_loc
  421. = do
  422. let dflags0 = hsc_dflags hsc_env0
  423. (input_basename, suffix) = splitExtension input_fn
  424. suffix' = drop 1 suffix -- strip off the .
  425. basename | Just b <- mb_basename = b
  426. | otherwise = input_basename
  427. -- Decide where dump files should go based on the pipeline output
  428. dflags = dflags0 { dumpPrefix = Just (basename ++ ".") }
  429. hsc_env = hsc_env0 {hsc_dflags = dflags}
  430. -- If we were given a -x flag, then use that phase to start from
  431. start_phase = fromMaybe (startPhase suffix') mb_phase
  432. -- We want to catch cases of "you can't get there from here" before
  433. -- we start the pipeline, because otherwise it will just run off the
  434. -- end.
  435. --
  436. -- There is a partial ordering on phases, where A < B iff A occurs
  437. -- before B in a normal compilation pipeline.
  438. when (not (start_phase `happensBefore` stop_phase)) $
  439. ghcError (UsageError
  440. ("cannot compile this file to desired target: "
  441. ++ input_fn))
  442. -- this is a function which will be used to calculate output file names
  443. -- as we go along (we partially apply it to some of its inputs here)
  444. let get_output_fn = getOutputFilename stop_phase output basename
  445. -- Execute the pipeline...
  446. (dflags', output_fn, maybe_loc) <-
  447. pipeLoop hsc_env start_phase stop_phase input_fn
  448. basename suffix' get_output_fn maybe_loc
  449. -- Sometimes, a compilation phase doesn't actually generate any output
  450. -- (eg. the CPP phase when -fcpp is not turned on). If we end on this
  451. -- stage, but we wanted to keep the output, then we have to explicitly
  452. -- copy the file, remembering to prepend a {-# LINE #-} pragma so that
  453. -- further compilation stages can tell what the original filename was.
  454. case output of
  455. Temporary ->
  456. return (dflags', output_fn)
  457. _other -> liftIO $
  458. do final_fn <- get_output_fn dflags' stop_phase maybe_loc
  459. when (final_fn /= output_fn) $ do
  460. let msg = ("Copying `" ++ output_fn ++"' to `" ++ final_fn ++ "'")
  461. line_prag = Just ("{-# LINE 1 \"" ++ input_fn ++ "\" #-}\n")
  462. copyWithHeader dflags msg line_prag output_fn final_fn
  463. return (dflags', final_fn)
  464. pipeLoop :: GhcMonad m =>
  465. HscEnv -> Phase -> Phase
  466. -> FilePath -> String -> Suffix
  467. -> (DynFlags -> Phase -> Maybe ModLocation -> IO FilePath)
  468. -> Maybe ModLocation
  469. -> m (DynFlags, FilePath, Maybe ModLocation)
  470. pipeLoop hsc_env phase stop_phase
  471. input_fn orig_basename orig_suff
  472. orig_get_output_fn maybe_loc
  473. | phase `eqPhase` stop_phase -- All done
  474. = return (hsc_dflags hsc_env, input_fn, maybe_loc)
  475. | not (phase `happensBefore` stop_phase)
  476. -- Something has gone wrong. We'll try to cover all the cases when
  477. -- this could happen, so if we reach here it is a panic.
  478. -- eg. it might happen if the -C flag is used on a source file that
  479. -- has {-# OPTIONS -fasm #-}.
  480. = panic ("pipeLoop: at phase " ++ show phase ++
  481. " but I wanted to stop at phase " ++ show stop_phase)
  482. | otherwise
  483. = do liftIO $ debugTraceMsg (hsc_dflags hsc_env) 4
  484. (ptext (sLit "Running phase") <+> ppr phase)
  485. (next_phase, dflags', maybe_loc, output_fn)
  486. <- runPhase phase stop_phase hsc_env orig_basename
  487. orig_suff input_fn orig_get_output_fn maybe_loc
  488. let hsc_env' = hsc_env {hsc_dflags = dflags'}
  489. pipeLoop hsc_env' next_phase stop_phase output_fn
  490. orig_basename orig_suff orig_get_output_fn maybe_loc
  491. getOutputFilename
  492. :: Phase -> PipelineOutput -> String
  493. -> DynFlags -> Phase{-next phase-} -> Maybe ModLocation -> IO FilePath
  494. getOutputFilename stop_phase output basename
  495. = func
  496. where
  497. func dflags next_phase maybe_location
  498. | is_last_phase, Persistent <- output = persistent_fn
  499. | is_last_phase, SpecificFile f <- output = return f
  500. | keep_this_output = persistent_fn
  501. | otherwise = newTempName dflags suffix
  502. where
  503. hcsuf = hcSuf dflags
  504. odir = objectDir dflags
  505. osuf = objectSuf dflags
  506. keep_hc = dopt Opt_KeepHcFiles dflags
  507. keep_raw_s = dopt Opt_KeepRawSFiles dflags
  508. keep_s = dopt Opt_KeepSFiles dflags
  509. keep_bc = dopt Opt_KeepLlvmFiles dflags
  510. myPhaseInputExt HCc = hcsuf
  511. myPhaseInputExt StopLn = osuf
  512. myPhaseInputExt other = phaseInputExt other
  513. is_last_phase = next_phase `eqPhase` stop_phase
  514. -- sometimes, we keep output from intermediate stages
  515. keep_this_output =
  516. case next_phase of
  517. StopLn -> True
  518. Mangle | keep_raw_s -> True
  519. As | keep_s -> True
  520. LlvmOpt | keep_bc -> True
  521. HCc | keep_hc -> True
  522. _other -> False
  523. suffix = myPhaseInputExt next_phase
  524. -- persistent object files get put in odir
  525. persistent_fn
  526. | StopLn <- next_phase = return odir_persistent
  527. | otherwise = return persistent
  528. persistent = basename <.> suffix
  529. odir_persistent
  530. | Just loc <- maybe_location = ml_obj_file loc
  531. | Just d <- odir = d </> persistent
  532. | otherwise = persistent
  533. -- -----------------------------------------------------------------------------
  534. -- | Each phase in the pipeline returns the next phase to execute, and the
  535. -- name of the file in which the output was placed.
  536. --
  537. -- We must do things dynamically this way, because we often don't know
  538. -- what the rest of the phases will be until part-way through the
  539. -- compilation: for example, an {-# OPTIONS -fasm #-} at the beginning
  540. -- of a source file can change the latter stages of the pipeline from
  541. -- taking the via-C route to using the native code generator.
  542. --
  543. runPhase :: GhcMonad m =>
  544. Phase -- ^ Do this phase first
  545. -> Phase -- ^ Stop just before this phase
  546. -> HscEnv
  547. -> String -- ^ basename of original input source
  548. -> String -- ^ its extension
  549. -> FilePath -- ^ name of file which contains the input to this phase.
  550. -> (DynFlags -> Phase -> Maybe ModLocation -> IO FilePath)
  551. -- ^ how to calculate the output filename
  552. -> Maybe ModLocation -- ^ the ModLocation, if we have one
  553. -> m (Phase, -- next phase
  554. DynFlags, -- new dynamic flags
  555. Maybe ModLocation, -- the ModLocation, if we have one
  556. FilePath) -- output filename
  557. -- Invariant: the output filename always contains the output
  558. -- Interesting case: Hsc when there is no recompilation to do
  559. -- Then the output filename is still a .o file
  560. -------------------------------------------------------------------------------
  561. -- Unlit phase
  562. runPhase (Unlit sf) _stop hsc_env _basename _suff input_fn get_output_fn maybe_loc
  563. = do
  564. let dflags = hsc_dflags hsc_env
  565. output_fn <- liftIO $ get_output_fn dflags (Cpp sf) maybe_loc
  566. let unlit_flags = getOpts dflags opt_L
  567. flags = map SysTools.Option unlit_flags ++
  568. [ -- The -h option passes the file name for unlit to
  569. -- put in a #line directive
  570. SysTools.Option "-h"
  571. -- cpp interprets \b etc as escape sequences,
  572. -- so we use / for filenames in pragmas
  573. , SysTools.Option $ reslash Forwards $ normalise input_fn
  574. , SysTools.FileOption "" input_fn
  575. , SysTools.FileOption "" output_fn
  576. ]
  577. liftIO $ SysTools.runUnlit dflags flags
  578. return (Cpp sf, dflags, maybe_loc, output_fn)
  579. -------------------------------------------------------------------------------
  580. -- Cpp phase : (a) gets OPTIONS out of file
  581. -- (b) runs cpp if necessary
  582. runPhase (Cpp sf) _stop hsc_env _basename _suff input_fn get_output_fn maybe_loc
  583. = do let dflags0 = hsc_dflags hsc_env
  584. src_opts <- liftIO $ getOptionsFromFile dflags0 input_fn
  585. (dflags1, unhandled_flags, warns)
  586. <- liftIO $ parseDynamicNoPackageFlags dflags0 src_opts
  587. checkProcessArgsResult unhandled_flags
  588. if not (xopt Opt_Cpp dflags1) then do
  589. -- we have to be careful to emit warnings only once.
  590. unless (dopt Opt_Pp dflags1) $ handleFlagWarnings dflags1 warns
  591. -- no need to preprocess CPP, just pass input file along
  592. -- to the next phase of the pipeline.
  593. return (HsPp sf, dflags1, maybe_loc, input_fn)
  594. else do
  595. output_fn <- liftIO $ get_output_fn dflags1 (HsPp sf) maybe_loc
  596. liftIO $ doCpp dflags1 True{-raw-} False{-no CC opts-} input_fn output_fn
  597. -- re-read the pragmas now that we've preprocessed the file
  598. -- See #2464,#3457
  599. src_opts <- liftIO $ getOptionsFromFile dflags0 output_fn
  600. (dflags2, unhandled_flags, warns)
  601. <- liftIO $ parseDynamicNoPackageFlags dflags0 src_opts
  602. unless (dopt Opt_Pp dflags2) $ handleFlagWarnings dflags2 warns
  603. -- the HsPp pass below will emit warnings
  604. checkProcessArgsResult unhandled_flags
  605. return (HsPp sf, dflags2, maybe_loc, output_fn)
  606. -------------------------------------------------------------------------------
  607. -- HsPp phase
  608. runPhase (HsPp sf) _stop hsc_env basename suff input_fn get_output_fn maybe_loc
  609. = do let dflags = hsc_dflags hsc_env
  610. if not (dopt Opt_Pp dflags) then
  611. -- no need to preprocess, just pass input file along
  612. -- to the next phase of the pipeline.
  613. return (Hsc sf, dflags, maybe_loc, input_fn)
  614. else do
  615. let hspp_opts = getOpts dflags opt_F
  616. let orig_fn = basename <.> suff
  617. output_fn <- liftIO $ get_output_fn dflags (Hsc sf) maybe_loc
  618. liftIO $ SysTools.runPp dflags
  619. ( [ SysTools.Option orig_fn
  620. , SysTools.Option input_fn
  621. , SysTools.FileOption "" output_fn
  622. ] ++
  623. map SysTools.Option hspp_opts
  624. )
  625. -- re-read pragmas now that we've parsed the file (see #3674)
  626. src_opts <- liftIO $ getOptionsFromFile dflags output_fn
  627. (dflags1, unhandled_flags, warns)
  628. <- liftIO $ parseDynamicNoPackageFlags dflags src_opts
  629. handleFlagWarnings dflags1 warns
  630. checkProcessArgsResult unhandled_flags
  631. return (Hsc sf, dflags1, maybe_loc, output_fn)
  632. -----------------------------------------------------------------------------
  633. -- Hsc phase
  634. -- Compilation of a single module, in "legacy" mode (_not_ under
  635. -- the direction of the compilation manager).
  636. runPhase (Hsc src_flavour) stop hsc_env basename suff input_fn get_output_fn _maybe_loc
  637. = do -- normal Hsc mode, not mkdependHS
  638. let dflags0 = hsc_dflags hsc_env
  639. -- we add the current directory (i.e. the directory in which
  640. -- the .hs files resides) to the include path, since this is
  641. -- what gcc does, and it's probably what you want.
  642. let current_dir = case takeDirectory basename of
  643. "" -> "." -- XXX Hack
  644. d -> d
  645. paths = includePaths dflags0
  646. dflags = dflags0 { includePaths = current_dir : paths }
  647. -- gather the imports and module name
  648. (hspp_buf,mod_name,imps,src_imps) <-
  649. case src_flavour of
  650. ExtCoreFile -> do -- no explicit imports in ExtCore input.
  651. m <- liftIO $ getCoreModuleName input_fn
  652. return (Nothing, mkModuleName m, [], [])
  653. _ -> do
  654. buf <- liftIO $ hGetStringBuffer input_fn
  655. (src_imps,imps,L _ mod_name) <- getImports dflags buf input_fn (basename <.> suff)
  656. return (Just buf, mod_name, imps, src_imps)
  657. -- Build a ModLocation to pass to hscMain.
  658. -- The source filename is rather irrelevant by now, but it's used
  659. -- by hscMain for messages. hscMain also needs
  660. -- the .hi and .o filenames, and this is as good a way
  661. -- as any to generate them, and better than most. (e.g. takes
  662. -- into accout the -osuf flags)
  663. location1 <- liftIO $ mkHomeModLocation2 dflags mod_name basename suff
  664. -- Boot-ify it if necessary
  665. let location2 | isHsBoot src_flavour = addBootSuffixLocn location1
  666. | otherwise = location1
  667. -- Take -ohi into account if present
  668. -- This can't be done in mkHomeModuleLocation because
  669. -- it only applies to the module being compiles
  670. let ohi = outputHi dflags
  671. location3 | Just fn <- ohi = location2{ ml_hi_file = fn }
  672. | otherwise = location2
  673. -- Take -o into account if present
  674. -- Very like -ohi, but we must *only* do this if we aren't linking
  675. -- (If we're linking then the -o applies to the linked thing, not to
  676. -- the object file for one module.)
  677. -- Note the nasty duplication with the same computation in compileFile above
  678. let expl_o_file = outputFile dflags
  679. location4 | Just ofile <- expl_o_file
  680. , isNoLink (ghcLink dflags)
  681. = location3 { ml_obj_file = ofile }
  682. | otherwise = location3
  683. o_file = ml_obj_file location4 -- The real object file
  684. -- Figure out if the source has changed, for recompilation avoidance.
  685. --
  686. -- Setting source_unchanged to True means that M.o seems
  687. -- to be up to date wrt M.hs; so no need to recompile unless imports have
  688. -- changed (which the compiler itself figures out).
  689. -- Setting source_unchanged to False tells the compiler that M.o is out of
  690. -- date wrt M.hs (or M.o doesn't exist) so we must recompile regardless.
  691. src_timestamp <- liftIO $ getModificationTime (basename <.> suff)
  692. let force_recomp = dopt Opt_ForceRecomp dflags
  693. hsc_lang = hscMaybeAdjustTarget dflags stop src_flavour (hscTarget dflags)
  694. source_unchanged <-
  695. if force_recomp || not (isStopLn stop)
  696. -- Set source_unchanged to False unconditionally if
  697. -- (a) recompilation checker is off, or
  698. -- (b) we aren't going all the way to .o file (e.g. ghc -S)
  699. then return False
  700. -- Otherwise look at file modification dates
  701. else do o_file_exists <- liftIO $ doesFileExist o_file
  702. if not o_file_exists
  703. then return False -- Need to recompile
  704. else do t2 <- liftIO $ getModificationTime o_file
  705. if t2 > src_timestamp
  706. then return True
  707. else return False
  708. -- get the DynFlags
  709. let next_phase = hscNextPhase dflags src_flavour hsc_lang
  710. output_fn <- liftIO $ get_output_fn dflags next_phase (Just location4)
  711. let dflags' = dflags { hscTarget = hsc_lang,
  712. hscOutName = output_fn,
  713. extCoreName = basename ++ ".hcr" }
  714. let hsc_env' = hsc_env {hsc_dflags = dflags'}
  715. -- Tell the finder cache about this module
  716. mod <- liftIO $ addHomeModuleToFinder hsc_env' mod_name location4
  717. -- Make the ModSummary to hand to hscMain
  718. let
  719. mod_summary = ModSummary { ms_mod = mod,
  720. ms_hsc_src = src_flavour,
  721. ms_hspp_file = input_fn,
  722. ms_hspp_opts = dflags,
  723. ms_hspp_buf = hspp_buf,
  724. ms_location = location4,
  725. ms_hs_date = src_timestamp,
  726. ms_obj_date = Nothing,
  727. ms_imps = imps,
  728. ms_srcimps = src_imps }
  729. -- run the compiler!
  730. result <- hscCompileOneShot hsc_env'
  731. mod_summary source_unchanged
  732. Nothing -- No iface
  733. Nothing -- No "module i of n" progress info
  734. case result of
  735. HscNoRecomp
  736. -> do liftIO $ SysTools.touch dflags' "Touching object file" o_file
  737. -- The .o file must have a later modification date
  738. -- than the source file (else we wouldn't be in HscNoRecomp)
  739. -- but we touch it anyway, to keep 'make' happy (we think).
  740. return (StopLn, dflags', Just location4, o_file)
  741. (HscRecomp hasStub _)
  742. -> do when hasStub $
  743. do stub_o <- compileStub hsc_env' mod location4
  744. liftIO $ consIORef v_Ld_inputs stub_o
  745. -- In the case of hs-boot files, generate a dummy .o-boot
  746. -- stamp file for the benefit of Make
  747. when (isHsBoot src_flavour) $
  748. liftIO $ SysTools.touch dflags' "Touching object file" o_file
  749. return (next_phase, dflags', Just location4, output_fn)
  750. -----------------------------------------------------------------------------
  751. -- Cmm phase
  752. runPhase CmmCpp _stop hsc_env _basename _suff input_fn get_output_fn maybe_loc
  753. = do
  754. let dflags = hsc_dflags hsc_env
  755. output_fn <- liftIO $ get_output_fn dflags Cmm maybe_loc
  756. liftIO $ doCpp dflags False{-not raw-} True{-include CC opts-} input_fn output_fn
  757. return (Cmm, dflags, maybe_loc, output_fn)
  758. runPhase Cmm stop hsc_env basename _ input_fn get_output_fn maybe_loc
  759. = do
  760. let dflags = hsc_dflags hsc_env
  761. let hsc_lang = hscMaybeAdjustTarget dflags stop HsSrcFile (hscTarget dflags)
  762. let next_phase = hscNextPhase dflags HsSrcFile hsc_lang
  763. output_fn <- liftIO $ get_output_fn dflags next_phase maybe_loc
  764. let dflags' = dflags { hscTarget = hsc_lang,
  765. hscOutName = output_fn,
  766. extCoreName = basename ++ ".hcr" }
  767. let hsc_env' = hsc_env {hsc_dflags = dflags'}
  768. hscCmmFile hsc_env' input_fn
  769. -- XXX: catch errors above and convert them into ghcError? Original
  770. -- code was:
  771. --
  772. --when (not ok) $ ghcError (PhaseFailed "cmm" (ExitFailure 1))
  773. return (next_phase, dflags, maybe_loc, output_fn)
  774. -----------------------------------------------------------------------------
  775. -- Cc phase
  776. -- we don't support preprocessing .c files (with -E) now. Doing so introduces
  777. -- way too many hacks, and I can't say I've ever used it anyway.
  778. runPhase cc_phase _stop hsc_env _basename _suff input_fn get_output_fn maybe_loc
  779. | cc_phase `eqPhase` Cc || cc_phase `eqPhase` Ccpp || cc_phase `eqPhase` HCc
  780. = do let dflags = hsc_dflags hsc_env
  781. let cc_opts = getOpts dflags opt_c
  782. hcc = cc_phase `eqPhase` HCc
  783. let cmdline_include_paths = includePaths dflags
  784. -- HC files have the dependent packages stamped into them
  785. pkgs <- if hcc then liftIO (getHCFilePackages input_fn) else return []
  786. -- add package include paths even if we're just compiling .c
  787. -- files; this is the Value Add(TM) that using ghc instead of
  788. -- gcc gives you :)
  789. pkg_include_dirs <- liftIO $ getPackageIncludePath dflags pkgs
  790. let include_paths = foldr (\ x xs -> "-I" : x : xs) []
  791. (cmdline_include_paths ++ pkg_include_dirs)
  792. let (md_c_flags, md_regd_c_flags) = machdepCCOpts dflags
  793. gcc_extra_viac_flags <- liftIO $ getExtraViaCOpts dflags
  794. let pic_c_flags = picCCOpts dflags
  795. let verb = getVerbFlag dflags
  796. -- cc-options are not passed when compiling .hc files. Our
  797. -- hc code doesn't not #include any header files anyway, so these
  798. -- options aren't necessary.
  799. pkg_extra_cc_opts <-
  800. if cc_phase `eqPhase` HCc
  801. then return []
  802. else liftIO $ getPackageExtraCcOpts dflags pkgs
  803. #ifdef darwin_TARGET_OS
  804. pkg_framework_paths <- liftIO $ getPackageFrameworkPath dflags pkgs
  805. let cmdline_framework_paths = frameworkPaths dflags
  806. let framework_paths = map ("-F"++)
  807. (cmdline_framework_paths ++ pkg_framework_paths)
  808. #endif
  809. let split_objs = dopt Opt_SplitObjs dflags
  810. split_opt | hcc && split_objs = [ "-DUSE_SPLIT_MARKERS" ]
  811. | otherwise = [ ]
  812. let cc_opt | optLevel dflags >= 2 = "-O2"
  813. | otherwise = "-O"
  814. -- Decide next phase
  815. let mangle = dopt Opt_DoAsmMangling dflags
  816. next_phase
  817. | hcc && mangle = Mangle
  818. | otherwise = As
  819. output_fn <- liftIO $ get_output_fn dflags next_phase maybe_loc
  820. let
  821. more_hcc_opts =
  822. #if i386_TARGET_ARCH
  823. -- on x86 the floating point regs have greater precision
  824. -- than a double, which leads to unpredictable results.
  825. -- By default, we turn this off with -ffloat-store unless
  826. -- the user specified -fexcess-precision.
  827. (if dopt Opt_ExcessPrecision dflags
  828. then []
  829. else [ "-ffloat-store" ]) ++
  830. #endif
  831. -- gcc's -fstrict-aliasing allows two accesses to memory
  832. -- to be considered non-aliasing if they have different types.
  833. -- This interacts badly with the C code we generate, which is
  834. -- very weakly typed, being derived from C--.
  835. ["-fno-strict-aliasing"]
  836. liftIO $ SysTools.runCc dflags (
  837. -- force the C compiler to interpret this file as C when
  838. -- compiling .hc files, by adding the -x c option.
  839. -- Also useful for plain .c files, just in case GHC saw a
  840. -- -x c option.
  841. [ SysTools.Option "-x", if cc_phase `eqPhase` Ccpp
  842. then SysTools.Option "c++"
  843. else SysTools.Option "c"] ++
  844. [ SysTools.FileOption "" input_fn
  845. , SysTools.Option "-o"
  846. , SysTools.FileOption "" output_fn
  847. ]
  848. ++ map SysTools.Option (
  849. md_c_flags
  850. ++ pic_c_flags
  851. #if defined(mingw32_TARGET_OS)
  852. -- Stub files generated for foreign exports references the runIO_closure
  853. -- and runNonIO_closure symbols, which are defined in the base package.
  854. -- These symbols are imported into the stub.c file via RtsAPI.h, and the
  855. -- way we do the import depends on whether we're currently compiling
  856. -- the base package or not.
  857. ++ (if thisPackage dflags == basePackageId
  858. then [ "-DCOMPILING_BASE_PACKAGE" ]
  859. else [])
  860. #endif
  861. #ifdef sparc_TARGET_ARCH
  862. -- We only support SparcV9 and better because V8 lacks an atomic CAS
  863. -- instruction. Note that the user can still override this
  864. -- (e.g., -mcpu=ultrasparc) as GCC picks the "best" -mcpu flag
  865. -- regardless of the ordering.
  866. --
  867. -- This is a temporary hack.
  868. ++ ["-mcpu=v9"]
  869. #endif
  870. ++ (if hcc && mangle
  871. then md_regd_c_flags
  872. else [])
  873. ++ (if hcc
  874. then if mangle
  875. then gcc_extra_viac_flags
  876. else filter (=="-fwrapv")
  877. gcc_extra_viac_flags
  878. -- still want -fwrapv even for unreg'd
  879. else [])
  880. ++ (if hcc
  881. then more_hcc_opts
  882. else [])
  883. ++ [ verb, "-S", "-Wimplicit", cc_opt ]
  884. ++ [ "-D__GLASGOW_HASKELL__="++cProjectVersionInt ]
  885. #ifdef darwin_TARGET_OS
  886. ++ framework_paths
  887. #endif
  888. ++ cc_opts
  889. ++ split_opt
  890. ++ include_paths
  891. ++ pkg_extra_cc_opts
  892. ))
  893. return (next_phase, dflags, maybe_loc, output_fn)
  894. -- ToDo: postprocess the output from gcc
  895. -----------------------------------------------------------------------------
  896. -- Mangle phase
  897. runPhase Mangle _stop hsc_env _basename _suff input_fn get_output_fn maybe_loc
  898. = do let dflags = hsc_dflags hsc_env
  899. let mangler_opts = getOpts dflags opt_m
  900. #if i386_TARGET_ARCH
  901. machdep_opts <- return [ show (stolen_x86_regs dflags) ]
  902. #else
  903. machdep_opts <- return []
  904. #endif
  905. let split = dopt Opt_SplitObjs dflags
  906. next_phase
  907. | split = SplitMangle
  908. | otherwise = As
  909. output_fn <- liftIO $ get_output_fn dflags next_phase maybe_loc
  910. liftIO $ SysTools.runMangle dflags (map SysTools.Option mangler_opts
  911. ++ [ SysTools.FileOption "" input_fn
  912. , SysTools.FileOption "" output_fn
  913. ]
  914. ++ map SysTools.Option machdep_opts)
  915. return (next_phase, dflags, maybe_loc, output_fn)
  916. -----------------------------------------------------------------------------
  917. -- Splitting phase
  918. runPhase SplitMangle _stop hsc_env _basename _suff input_fn _get_output_fn maybe_loc
  919. = liftIO $
  920. do -- tmp_pfx is the prefix used for the split .s files
  921. -- We also use it as the file to contain the no. of split .s files (sigh)
  922. let dflags = hsc_dflags hsc_env
  923. split_s_prefix <- SysTools.newTempName dflags "split"
  924. let n_files_fn = split_s_prefix
  925. SysTools.runSplit dflags
  926. [ SysTools.FileOption "" input_fn
  927. , SysTools.FileOption "" split_s_prefix
  928. , SysTools.FileOption "" n_files_fn
  929. ]
  930. -- Save the number of split files for future references
  931. s <- readFile n_files_fn
  932. let n_files = read s :: Int
  933. dflags' = dflags { splitInfo = Just (split_s_prefix, n_files) }
  934. -- Remember to delete all these files
  935. addFilesToClean dflags' [ split_s_prefix ++ "__" ++ show n ++ ".s"
  936. | n <- [1..n_files]]
  937. return (SplitAs, dflags', maybe_loc, "**splitmangle**")
  938. -- we don't use the filename
  939. -----------------------------------------------------------------------------
  940. -- As phase
  941. runPhase As _stop hsc_env _basename _suff input_fn get_output_fn maybe_loc
  942. = liftIO $
  943. do let dflags = hsc_dflags hsc_env
  944. let as_opts = getOpts dflags opt_a
  945. let cmdline_include_paths = includePaths dflags
  946. output_fn <- get_output_fn dflags StopLn maybe_loc
  947. -- we create directories for the object file, because it
  948. -- might be a hierarchical module.
  949. createDirectoryHierarchy (takeDirectory output_fn)
  950. let (md_c_flags, _) = machdepCCOpts dflags
  951. SysTools.runAs dflags
  952. (map SysTools.Option as_opts
  953. ++ [ SysTools.Option ("-I" ++ p) | p <- cmdline_include_paths ]
  954. #ifdef sparc_TARGET_ARCH
  955. -- We only support SparcV9 and better because V8 lacks an atomic CAS
  956. -- instruction so we have to make sure that the assembler accepts the
  957. -- instruction set. Note that the user can still override this
  958. -- (e.g., -mcpu=ultrasparc). GCC picks the "best" -mcpu flag
  959. -- regardless of the ordering.
  960. --
  961. -- This is a temporary hack.
  962. ++ [ SysTools.Option "-mcpu=v9" ]
  963. #endif
  964. ++ [ SysTools.Option "-c"
  965. , SysTools.FileOption "" input_fn
  966. , SysTools.Option "-o"
  967. , SysTools.FileOption "" output_fn
  968. ]
  969. ++ map SysTools.Option md_c_flags)
  970. return (StopLn, dflags, maybe_loc, output_fn)
  971. runPhase SplitAs _stop hsc_env _basename _suff _input_fn get_output_fn maybe_loc
  972. = liftIO $ do
  973. let dflags = hsc_dflags hsc_env
  974. output_fn <- get_output_fn dflags StopLn maybe_loc
  975. let base_o = dropExtension output_fn
  976. osuf = objectSuf dflags
  977. split_odir = base_o ++ "_" ++ osuf ++ "_split"
  978. createDirectoryHierarchy split_odir
  979. -- remove M_split/ *.o, because we're going to archive M_split/ *.o
  980. -- later and we don't want to pick up any old objects.
  981. fs <- getDirectoryContents split_odir
  982. mapM_ removeFile $ map (split_odir </>) $ filter (osuf `isSuffixOf`) fs
  983. let as_opts = getOpts dflags opt_a
  984. let (split_s_prefix, n) = case splitInfo dflags of
  985. Nothing -> panic "No split info"
  986. Just x -> x
  987. let split_s n = split_s_prefix ++ "__" ++ show n <.> "s"
  988. split_obj n = split_odir </>
  989. takeFileName base_o ++ "__" ++ show n <.> osuf
  990. let (md_c_flags, _) = machdepCCOpts dflags
  991. let assemble_file n
  992. = SysTools.runAs dflags
  993. (map SysTools.Option as_opts ++
  994. #ifdef sparc_TARGET_ARCH
  995. -- We only support SparcV9 and better beca

Large files files are truncated, but you can click here to view the full file