+ -> IO result
+
+data HsCompiler a
+ = HsCompiler {
+ -- | Called when no recompilation is necessary.
+ hscNoRecomp :: ModIface
+ -> Hsc a,
+
+ -- | Called to recompile the module.
+ hscRecompile :: ModSummary -> Maybe Fingerprint
+ -> Hsc a,
+
+ hscBackend :: TcGblEnv -> ModSummary -> Maybe Fingerprint
+ -> Hsc a,
+
+ -- | Code generation for Boot modules.
+ hscGenBootOutput :: TcGblEnv -> ModSummary -> Maybe Fingerprint
+ -> Hsc a,
+
+ -- | Code generation for normal modules.
+ hscGenOutput :: ModGuts -> ModSummary -> Maybe Fingerprint
+ -> Hsc a
+ }
+
+genericHscCompile :: HsCompiler a
+ -> (HscEnv -> Maybe (Int,Int) -> Bool -> ModSummary -> IO ())
+ -> HscEnv -> ModSummary -> Bool
+ -> Maybe ModIface -> Maybe (Int, Int)
+ -> IO a
+genericHscCompile compiler hscMessage hsc_env
+ mod_summary source_unchanged
+ mb_old_iface0 mb_mod_index
+ = do
+ (recomp_reqd, mb_checked_iface)
+ <- {-# SCC "checkOldIface" #-}
+ checkOldIface hsc_env mod_summary
+ source_unchanged mb_old_iface0
+ -- save the interface that comes back from checkOldIface.
+ -- In one-shot mode we don't have the old iface until this
+ -- point, when checkOldIface reads it from the disk.
+ let mb_old_hash = fmap mi_iface_hash mb_checked_iface
+ case mb_checked_iface of
+ Just iface | not recomp_reqd
+ -> do hscMessage hsc_env mb_mod_index False mod_summary
+ runHsc hsc_env $ hscNoRecomp compiler iface
+ _otherwise
+ -> do hscMessage hsc_env mb_mod_index True mod_summary
+ runHsc hsc_env $ hscRecompile compiler mod_summary mb_old_hash
+
+hscCheckRecompBackend :: HsCompiler a -> TcGblEnv -> Compiler a
+hscCheckRecompBackend compiler tc_result
+ hsc_env mod_summary source_unchanged mb_old_iface _m_of_n
+ = do
+ (recomp_reqd, mb_checked_iface)
+ <- {-# SCC "checkOldIface" #-}
+ checkOldIface hsc_env mod_summary
+ source_unchanged mb_old_iface
+
+ let mb_old_hash = fmap mi_iface_hash mb_checked_iface
+ case mb_checked_iface of
+ Just iface | not recomp_reqd
+ -> runHsc hsc_env $
+ hscNoRecomp compiler
+ iface{ mi_globals = Just (tcg_rdr_env tc_result) }
+ _otherwise
+ -> runHsc hsc_env $
+ hscBackend compiler tc_result mod_summary mb_old_hash
+
+genericHscRecompile :: HsCompiler a
+ -> ModSummary -> Maybe Fingerprint
+ -> Hsc a
+genericHscRecompile compiler mod_summary mb_old_hash
+ | ExtCoreFile <- ms_hsc_src mod_summary =
+ panic "GHC does not currently support reading External Core files"
+ | otherwise = do
+ tc_result <- hscFileFrontEnd mod_summary
+ hscBackend compiler tc_result mod_summary mb_old_hash
+
+genericHscBackend :: HsCompiler a
+ -> TcGblEnv -> ModSummary -> Maybe Fingerprint
+ -> Hsc a
+genericHscBackend compiler tc_result mod_summary mb_old_hash
+ | HsBootFile <- ms_hsc_src mod_summary =
+ hscGenBootOutput compiler tc_result mod_summary mb_old_hash
+ | otherwise = do
+ guts <- hscDesugar' mod_summary tc_result
+ hscGenOutput compiler guts mod_summary mb_old_hash
+
+compilerBackend :: HsCompiler a -> TcGblEnv -> Compiler a
+compilerBackend comp tcg hsc_env ms' _ _mb_old_iface _ =
+ runHsc hsc_env $
+ hscBackend comp tcg ms' Nothing