- -------------------
- ; let
- ModDetails{md_binds=binds, md_types=env_tc} = prepd_details
-
- local_tycons = typeEnvTyCons env_tc
- local_classes = typeEnvClasses env_tc
-
- imported_module_names =
- filter (/= gHC_PRIM_Name) $
- map ideclName (hsModuleImports rdr_module)
- -- eek! doesn't this keep rdr_module live until code generation?
- -- SDM 3/2002
-
- mod_name_to_Module nm
- = do m <- findModule nm ; return (fst (fromJust m))
-
- (h_code, c_code, headers, fe_binders) = foreign_stuff
-
- -- turn the list of headers requested in foreign import
- -- declarations into a string suitable for emission into generated
- -- C code...
- --
- foreign_headers =
- unlines
- . map (\fname -> "#include \"" ++ unpackFS fname ++ "\"")
- . reverse
- $ headers
-
- -- ...and add the string to the headers requested via command line
- -- options
- --
- ; fhdrs <- readIORef v_HCHeader
- ; writeIORef v_HCHeader (fhdrs ++ foreign_headers)
-
- ; imported_modules <- mapM mod_name_to_Module imported_module_names
-
- ; (stub_h_exists, stub_c_exists, maybe_bcos, final_iface )
- <- if toInterp
-#ifdef GHCI
- 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
-
- ------------------ Create f-x-dynamic C-side stuff ---
- (istub_h_exists, istub_c_exists)
- <- outputForeignStubs dflags c_code h_code
-
- return ( istub_h_exists, istub_c_exists,
- Just (bcos,itbl_env), final_iface )
-#else
- then error "GHC not compiled with interpreter"
-#endif
-
- 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
- if toNothing
- then do
- return (False, False, Nothing, final_iface)
- else do
- ------------------ 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)