+
+-- -----------------------------------------------------------------------------
+-- Misc.
+
+doCpp :: Bool -> Bool -> FilePath -> FilePath -> IO ()
+doCpp raw include_cc_opts input_fn output_fn = do
+ hscpp_opts <- getOpts opt_P
+
+ cmdline_include_paths <- readIORef v_Include_paths
+
+ pkg_include_dirs <- getPackageIncludePath []
+ let include_paths = foldr (\ x xs -> "-I" : x : xs) []
+ (cmdline_include_paths ++ pkg_include_dirs)
+
+ verb <- getVerbFlag
+
+ cc_opts <- if not include_cc_opts
+ then return []
+ else do optc <- getOpts opt_c
+ (md_c_flags, _) <- machdepCCOpts
+ return (optc ++ md_c_flags)
+
+ let cpp_prog args | raw = SysTools.runCpp args
+ | otherwise = SysTools.runCc (SysTools.Option "-E" : args)
+
+ cpp_prog ([SysTools.Option verb]
+ ++ map SysTools.Option include_paths
+ ++ map SysTools.Option hsSourceCppOpts
+ ++ map SysTools.Option hscpp_opts
+ ++ map SysTools.Option cc_opts
+ ++ [ SysTools.Option "-x"
+ , SysTools.Option "c"
+ , SysTools.Option input_fn
+ -- We hackily use Option instead of FileOption here, so that the file
+ -- name is not back-slashed on Windows. cpp is capable of
+ -- dealing with / in filenames, so it works fine. Furthermore
+ -- if we put in backslashes, cpp outputs #line directives
+ -- with *double* backslashes. And that in turn means that
+ -- our error messages get double backslashes in them.
+ -- In due course we should arrange that the lexer deals
+ -- with these \\ escapes properly.
+ , SysTools.Option "-o"
+ , SysTools.FileOption "" output_fn
+ ])
+
+-- -----------------------------------------------------------------------------
+-- Misc.
+
+hscNextPhase :: HscLang -> IO Phase
+hscNextPhase hsc_lang = do
+ split <- readIORef v_Split_object_files
+ return (case hsc_lang of
+ HscC -> HCc
+ HscAsm | split -> SplitMangle
+ | otherwise -> As
+ HscNothing -> HCc -- dummy (no output will be generated)
+ HscInterpreted -> HCc -- "" ""
+ _other -> HCc -- "" ""
+ )
+
+hscMaybeAdjustLang :: HscLang -> IO HscLang
+hscMaybeAdjustLang current_hsc_lang = do
+ todo <- readIORef v_GhcMode
+ keep_hc <- readIORef v_Keep_hc_files
+ let hsc_lang
+ -- don't change the lang if we're interpreting
+ | current_hsc_lang == HscInterpreted = current_hsc_lang
+ -- force -fvia-C if we are being asked for a .hc file
+ | todo == StopBefore HCc || keep_hc = HscC
+ -- otherwise, stick to the plan
+ | otherwise = current_hsc_lang
+ return hsc_lang