- ; let
- ModDetails{md_binds=binds, md_types=env_tc} = prepd_details
-
- local_tycons = typeEnvTyCons env_tc
- local_classes = typeEnvClasses env_tc
-
- imported_module_names = map ideclName (hsModuleImports rdr_module)
-
- mod_name_to_Module nm
- = do m <- findModule nm ; return (fst (fromJust m))
-
- (h_code,c_code,fe_binders) = foreign_stuff
-
- ; imported_modules <- mapM mod_name_to_Module imported_module_names
-
- ; (stub_h_exists, stub_c_exists, maybe_bcos, final_iface )
- <- if toInterp
- then do
- ----------------- Generate byte code ------------------
- (bcos,itbl_env) <- byteCodeGen dflags binds
- local_tycons local_classes
-
- -- Fill in the code-gen info
- writeIORef cg_info_ref (Just emptyNameEnv)
-
- ------------------ BUILD THE NEW ModIface ------------
- final_iface <- _scc_ "MkFinalIface"
- mkFinalIface ghci_mode dflags location
- maybe_checked_iface new_iface tidy_details
-
- return ( False, False, Just (bcos,itbl_env), final_iface )
-
- else do
- ----------------- Convert to STG ------------------
- (stg_binds, cost_centre_info, stg_back_end_info)
- <- _scc_ "CoreToStg"
- myCoreToStg dflags this_mod binds
-
- -- Fill in the code-gen info for the earlier tidyCorePgm
- writeIORef cg_info_ref (Just stg_back_end_info)
-
- ------------------ BUILD THE NEW ModIface ------------
- final_iface <- _scc_ "MkFinalIface"
- mkFinalIface ghci_mode dflags location
- maybe_checked_iface new_iface tidy_details
-
- ------------------ Code generation ------------------
- abstractC <- _scc_ "CodeGen"
- codeGen dflags this_mod imported_modules
- cost_centre_info fe_binders
- local_tycons stg_binds
-
- ------------------ Code output -----------------------
- (stub_h_exists, stub_c_exists)
- <- codeOutput dflags this_mod local_tycons
- binds stg_binds
- c_code h_code abstractC
-
- return (stub_h_exists, stub_c_exists, Nothing, final_iface)
-
- ; let final_details = tidy_details {md_binds = []}
-
-
- -- and the answer is ...
- ; return (HscRecomp pcs_final
- final_details
+ -- BUILD THE NEW ModIface and ModDetails
+ -- and emit external core if necessary
+ -- This has to happen *after* code gen so that the back-end
+ -- info has been set. Not yet clear if it matters waiting
+ -- until after code output
+ ; new_iface <- {-# SCC "MkFinalIface" #-}
+ mkIface hsc_env (ms_location mod_summary)
+ maybe_checked_iface tidy_result
+
+ -- Space leak reduction: throw away the new interface if
+ -- we're in one-shot mode; we won't be needing it any
+ -- more.
+ ; final_iface <-
+ if one_shot then return (error "no final iface")
+ else return new_iface
+
+ -- Build the final ModDetails (except in one-shot mode, where
+ -- we won't need this information after compilation).
+ ; final_details <-
+ if one_shot then return (error "no final details")
+ else return $! ModDetails {
+ md_types = mg_types tidy_result,
+ md_insts = mg_insts tidy_result,
+ md_rules = mg_rules tidy_result }
+
+ -------------------
+ -- CONVERT TO STG and COMPLETE CODE GENERATION
+ ; (stub_h_exists, stub_c_exists, maybe_bcos)
+ <- hscCodeGen dflags tidy_result
+
+ -- And the answer is ...
+ ; dumpIfaceStats hsc_env
+
+ ; return (HscRecomp final_details