- ; 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
- final_iface
- stub_h_exists stub_c_exists
- maybe_bcos)
- }}}}}}}
+ ; (warns, maybe_ds_result) <- _scc_ "DeSugar"
+ deSugar hsc_env tc_result
+ ; msg_act (warns, emptyBag)
+ ; case maybe_ds_result of
+ Nothing -> return (Left HscFail);
+ Just ds_result -> return (Right ds_result);
+ }}}
+
+hscBackEnd dflags
+ ModGuts{ -- This is the last use of the ModGuts in a compilation.
+ -- From now on, we just use the bits we need.
+ mg_module = this_mod,
+ mg_binds = core_binds,
+ mg_types = type_env,
+ mg_dir_imps = dir_imps,
+ mg_foreign = foreign_stubs,
+ mg_deps = dependencies } = do {
+
+ -------------------
+ -- PREPARE FOR CODE GENERATION
+ -- Do saturation and convert to A-normal form
+ prepd_binds <- _scc_ "CorePrep"
+ corePrepPgm dflags core_binds type_env;
+
+ case dopt_HscLang dflags of
+ HscNothing -> return (False, False, Nothing)
+
+ HscInterpreted ->
+#ifdef GHCI
+ do ----------------- Generate byte code ------------------
+ comp_bc <- byteCodeGen dflags prepd_binds type_env
+
+ ------------------ Create f-x-dynamic C-side stuff ---
+ (istub_h_exists, istub_c_exists)
+ <- outputForeignStubs dflags foreign_stubs
+
+ return ( istub_h_exists, istub_c_exists, Just comp_bc )
+#else
+ panic "GHC not compiled with interpreter"
+#endif
+
+ other ->
+ do
+ ----------------- Convert to STG ------------------
+ (stg_binds, cost_centre_info) <- _scc_ "CoreToStg"
+ myCoreToStg dflags this_mod prepd_binds
+
+ ------------------ Code generation ------------------
+ abstractC <- _scc_ "CodeGen"
+ codeGen dflags this_mod type_env foreign_stubs
+ dir_imps cost_centre_info stg_binds
+
+ ------------------ Code output -----------------------
+ (stub_h_exists, stub_c_exists)
+ <- codeOutput dflags this_mod foreign_stubs
+ dependencies abstractC
+
+ return (stub_h_exists, stub_c_exists, Nothing)
+ }
+
+
+hscCmmFile :: DynFlags -> FilePath -> IO Bool
+hscCmmFile dflags filename = do
+ maybe_cmm <- parseCmmFile dflags filename
+ case maybe_cmm of
+ Nothing -> return False
+ Just cmm -> do
+ codeOutput dflags no_mod NoStubs noDependencies [cmm]
+ return True
+ where
+ no_mod = panic "hscCmmFile: no_mod"
+