+import qualified Module ( moduleName )
+
+#ifdef DEBUG
+import Outputable
+#endif
+
+import DATA_IOREF ( readIORef )
+\end{code}
+
+\begin{code}
+codeGen :: DynFlags
+ -> Module
+ -> TypeEnv
+ -> ForeignStubs
+ -> [Module] -- directly-imported modules
+ -> CollectedCCs -- (Local/global) cost-centres needing declaring/registering.
+ -> [(StgBinding,[(Id,[Id])])] -- Bindings to convert, with SRTs
+ -> IO AbstractC -- Output
+
+codeGen dflags this_mod type_env foreign_stubs imported_mods
+ cost_centre_info stg_binds
+ = do
+ showPass dflags "CodeGen"
+ fl_uniqs <- mkSplitUniqSupply 'f'
+ way <- readIORef v_Build_tag
+ mb_main_mod <- readIORef v_MainModIs
+
+ let
+ tycons = typeEnvTyCons type_env
+ data_tycons = filter isDataTyCon tycons
+
+ mapM_ (\x -> seq x (return ())) data_tycons
+
+ let
+
+ cinfo = MkCompInfo this_mod
+
+ datatype_stuff = genStaticConBits cinfo data_tycons
+ code_stuff = initC cinfo (mapCs cgTopBinding stg_binds)
+ init_stuff = mkModuleInit way cost_centre_info
+ this_mod mb_main_mod
+ foreign_stubs imported_mods
+
+ abstractC = mkAbstractCs [ maybeSplitCode,
+ init_stuff,
+ code_stuff,
+ datatype_stuff]
+ -- Put datatype_stuff after code_stuff, because the
+ -- datatype closure table (for enumeration types) to
+ -- (say) PrelBase_True_closure, which is defined in
+ -- code_stuff
+
+ dumpIfSet_dyn dflags Opt_D_dump_absC "Abstract C" (dumpRealC abstractC)
+
+ return $! flattenAbsC fl_uniqs abstractC