-codeGen :: FAST_STRING -- module name
- -> ([CostCentre], -- local cost-centres needing declaring/registering
- [CostCentre]) -- "extern" cost-centres needing declaring
- -> [Module] -- import names
- -> [TyCon] -- tycons with data constructors to convert
- -> FiniteMap TyCon [(Bool, [Maybe Type])]
- -- tycon specialisation info
- -> [StgBinding] -- bindings to convert
- -> AbstractC -- output
-
-codeGen mod_name (local_CCs, extern_CCs) import_names gen_tycons tycon_specs stg_pgm
+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
+\end{code}
+
+%************************************************************************
+%* *
+\subsection[codegen-init]{Module initialisation code}
+%* *
+%************************************************************************
+
+\begin{code}
+mkModuleInit
+ :: String -- the "way"
+ -> CollectedCCs -- cost centre info
+ -> Module
+ -> Maybe String -- Just m ==> we have flag: -main-is Foo.baz
+ -> ForeignStubs
+ -> [Module]
+ -> AbstractC
+mkModuleInit way cost_centre_info this_mod mb_main_mod foreign_stubs imported_mods