1 /* -----------------------------------------------------------------------------
2 * $Id: RtsStartup.c,v 1.17 1999/07/06 15:33:23 simonmar Exp $
4 * (c) The GHC Team, 1998-1999
6 * Main function for a standalone Haskell program.
8 * ---------------------------------------------------------------------------*/
14 #include "Storage.h" /* initStorage, exitStorage */
15 #include "StablePriv.h" /* initStablePtrTable */
16 #include "Schedule.h" /* initScheduler */
17 #include "Stats.h" /* initStats */
21 #if defined(PROFILING)
24 # include "DebugProf.h"
36 struct RTS_FLAGS RtsFlags;
38 static int rts_has_started_up = 0;
41 startupHaskell(int argc, char *argv[])
43 #ifdef ENABLE_WIN32_DLL_SUPPORT
47 /* To avoid repeated initialisations of the RTS */
48 if (rts_has_started_up)
54 int nPEs = 0; /* Number of PEs */
57 /* The very first thing we do is grab the start time...just in case we're
58 * collecting timing statistics.
64 *The parallel system needs to be initialised and synchronised before
67 if (*argv[0] == '-') { /* Look to see whether we're the Main Thread */
68 IAmMainThread = rtsTrue;
69 argv++; argc--; /* Strip off flag argument */
70 /* fprintf(stderr, "I am Main Thread\n"); */
73 * Grab the number of PEs out of the argument vector, and
74 * eliminate it from further argument processing.
79 initEachPEHook(); /* HWL: hook to be execed on each PE */
83 /* Set the RTS flags to default values. */
84 initRtsFlagsDefaults();
86 /* Call the user hook to reset defaults, if present */
89 /* Parse the flags, separating the RTS flags from the programs args */
90 setupRtsFlags(&argc, argv, &rts_argc, rts_argv);
95 /* Initialise the parallel system -- before initHeap! */
97 /* And start GranSim profiling if required: omitted for now
98 *if (Rtsflags.ParFlags.granSimStats)
99 *init_gr_profiling(rts_argc, rts_argv, prog_argc, prog_argv);
103 /* initialize the storage manager */
106 /* initialise the stable pointer table */
107 initStablePtrTable();
109 #if defined(PROFILING) || defined(DEBUG)
113 /* Initialise the scheduler */
116 /* Initialise the stats department */
123 /* When the RTS and Prelude live in separate DLLs,
124 we need to patch up the char- and int-like tables
125 that the RTS keep after both DLLs have been loaded,
126 filling in the tables with references to where the
127 static info tables have been loaded inside the running
130 #ifdef ENABLE_WIN32_DLL_SUPPORT
132 (CHARLIKE_closure[i]).header.info = (const StgInfoTable*)&Czh_static_info;
135 (INTLIKE_closure[i]).header.info = (const StgInfoTable*)&Izh_static_info;
138 /* Record initialization times */
143 * Shutting down the RTS - two ways of doing this, one which
144 * calls exit(), one that doesn't.
146 * (shutdownHaskellAndExit() is called by System.exitWith).
149 shutdownHaskellAndExit(int n)
157 shutdownHaskell(void)
159 if (!rts_has_started_up)
162 /* Finalize any remaining weak pointers */
163 finalizeWeakPointersNow();
167 if (!RTSflags.GranFlags.granSimStats_suppressed)
171 /* clean up things from the storage manager's point of view */
174 #if defined(PROFILING) || defined(DEBUG)
178 #if defined(PROFILING)
179 report_ccs_profiling( );
182 #if defined(TICKY_TICKY)
183 if (RtsFlags.TickyFlags.showTickyStats) PrintTickyInfo();
186 rts_has_started_up=0;
191 * called from STG-land to exit the program