1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2004
5 * Top-level include file for the RTS itself
7 * ---------------------------------------------------------------------------*/
24 /* Assume that a flexible array member at the end of a struct
25 * can be defined thus: T arr[]; */
26 #define FLEXIBLE_ARRAY
28 /* Assume that it must be defined thus: T arr[0]; */
29 #define FLEXIBLE_ARRAY 0
32 /* Fix for mingw stat problem (done here so it's early enough) */
33 #ifdef mingw32_HOST_OS
38 * We often want to know the size of something in units of an
39 * StgWord... (rounded up, of course!)
41 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
44 * It's nice to be able to grep for casts
46 #define stgCast(ty,e) ((ty)(e))
48 /* -----------------------------------------------------------------------------
49 Assertions and Debuggery
50 -------------------------------------------------------------------------- */
53 #define ASSERT(predicate) /* nothing */
56 extern void _assertFail (char *, unsigned int);
58 #define ASSERT(predicate) \
62 _assertFail(__FILE__, __LINE__)
66 * Use this on the RHS of macros which expand to nothing
67 * to make sure that the macro can be used in a context which
68 * demands a non-empty statement.
71 #define doNothing() do { } while (0)
75 #define USED_IF_NOT_DEBUG STG_UNUSED
77 #define USED_IF_DEBUG STG_UNUSED
78 #define USED_IF_NOT_DEBUG
82 #define USED_IF_THREADS
83 #define USED_IF_NOT_THREADS STG_UNUSED
85 #define USED_IF_THREADS STG_UNUSED
86 #define USED_IF_NOT_THREADS
89 /* -----------------------------------------------------------------------------
90 Include everything STG-ish
91 -------------------------------------------------------------------------- */
93 /* System headers: stdlib.h is eeded so that we can use NULL. It must
94 * come after MachRegs.h, because stdlib.h might define some inline
95 * functions which may only be defined after register variables have
100 /* Global constaints */
101 #include "Constants.h"
103 /* Profiling information */
105 #include "StgLdvProf.h"
107 /* Storage format definitions */
109 #include "Closures.h"
110 #include "Liveness.h"
111 #include "ClosureTypes.h"
112 #include "InfoTables.h"
115 /* Info tables, closures & code fragments defined in the RTS */
116 #include "StgMiscClosures.h"
118 /* Simulated-parallel information */
121 /* Parallel information */
122 #include "Parallel.h"
123 #include "OSThreads.h"
126 /* STG/Optimised-C related stuff */
132 /* Macros for STG/C code */
133 #include "ClosureMacros.h"
134 #include "StgTicky.h"
137 /* Runtime-system hooks */
139 #include "RtsMessages.h"
141 #include "ieee-flpt.h"
145 /* Misc stuff without a home */
146 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
147 DLL_IMPORT_RTS extern int prog_argc;
148 DLL_IMPORT_RTS extern char *prog_name;
150 extern void stackOverflow(void);
152 extern void __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
153 extern void __decodeFloat (MP_INT *man, I_ *_exp, StgFloat flt);
155 #if defined(WANT_DOTNET_SUPPORT)
156 #include "DNInvoke.h"
159 /* Initialising the whole adjustor thunk machinery. */
160 extern void initAdjustor(void);
162 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
164 /* -----------------------------------------------------------------------------
166 -------------------------------------------------------------------------- */
168 /* 255 is allegedly used by dynamic linkers to report linking failure */
169 #define EXIT_INTERNAL_ERROR 254
170 #define EXIT_DEADLOCK 253
171 #define EXIT_INTERRUPTED 252
172 #define EXIT_HEAPOVERFLOW 251
173 #define EXIT_KILLED 250
175 /* -----------------------------------------------------------------------------
176 Miscellaneous garbage
177 -------------------------------------------------------------------------- */
179 /* declarations for runtime flags/values */
180 #define MAX_RTS_ARGS 32
182 /* -----------------------------------------------------------------------------
183 Assertions and Debuggery
184 -------------------------------------------------------------------------- */
186 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
188 /* -----------------------------------------------------------------------------
189 Assertions and Debuggery
190 -------------------------------------------------------------------------- */
193 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
195 #define IF_DEBUG(c,s) doNothing()
199 #define DEBUG_ONLY(s) s
201 #define DEBUG_ONLY(s) doNothing()
204 #if defined(GRAN) && defined(DEBUG)
205 #define IF_GRAN_DEBUG(c,s) if (RtsFlags.GranFlags.Debug.c) { s; }
207 #define IF_GRAN_DEBUG(c,s) doNothing()
210 #if defined(PAR) && defined(DEBUG)
211 #define IF_PAR_DEBUG(c,s) if (RtsFlags.ParFlags.Debug.c) { s; }
213 #define IF_PAR_DEBUG(c,s) doNothing()
216 /* -----------------------------------------------------------------------------
217 Useful macros and inline functions
218 -------------------------------------------------------------------------- */
220 #if defined(__GNUC__)
221 #define SUPPORTS_TYPEOF
224 #if defined(SUPPORTS_TYPEOF)
225 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
226 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
228 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
229 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
232 /* -------------------------------------------------------------------------- */