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 #if defined(SMP) || defined(THREADED_RTS)
33 #define RTS_SUPPORTS_THREADS 1
36 /* Fix for mingw stat problem (done here so it's early enough) */
37 #ifdef mingw32_HOST_OS
42 * We often want to know the size of something in units of an
43 * StgWord... (rounded up, of course!)
45 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
48 * It's nice to be able to grep for casts
50 #define stgCast(ty,e) ((ty)(e))
52 /* -----------------------------------------------------------------------------
53 Assertions and Debuggery
54 -------------------------------------------------------------------------- */
57 #define ASSERT(predicate) /* nothing */
60 extern void _assertFail (char *, unsigned int);
62 #define ASSERT(predicate) \
66 _assertFail(__FILE__, __LINE__)
70 * Use this on the RHS of macros which expand to nothing
71 * to make sure that the macro can be used in a context which
72 * demands a non-empty statement.
75 #define doNothing() do { } while (0)
77 /* -----------------------------------------------------------------------------
78 Include everything STG-ish
79 -------------------------------------------------------------------------- */
81 /* System headers: stdlib.h is eeded so that we can use NULL. It must
82 * come after MachRegs.h, because stdlib.h might define some inline
83 * functions which may only be defined after register variables have
88 /* Global constaints */
89 #include "Constants.h"
91 /* Profiling information */
93 #include "StgLdvProf.h"
95 /* Storage format definitions */
99 #include "ClosureTypes.h"
100 #include "InfoTables.h"
103 /* Info tables, closures & code fragments defined in the RTS */
104 #include "StgMiscClosures.h"
106 /* Simulated-parallel information */
109 /* Parallel information */
110 #include "Parallel.h"
112 /* STG/Optimised-C related stuff */
123 /* Macros for STG/C code */
124 #include "ClosureMacros.h"
125 #include "StgTicky.h"
128 /* Runtime-system hooks */
130 #include "RtsMessages.h"
132 #include "ieee-flpt.h"
136 /* Misc stuff without a home */
137 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
138 DLL_IMPORT_RTS extern int prog_argc;
139 DLL_IMPORT_RTS extern char *prog_name;
141 extern void stackOverflow(void);
143 extern void __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
144 extern void __decodeFloat (MP_INT *man, I_ *_exp, StgFloat flt);
146 #if defined(WANT_DOTNET_SUPPORT)
147 #include "DNInvoke.h"
150 /* Initialising the whole adjustor thunk machinery. */
151 extern void initAdjustor(void);
153 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
155 /* -----------------------------------------------------------------------------
157 -------------------------------------------------------------------------- */
159 /* 255 is allegedly used by dynamic linkers to report linking failure */
160 #define EXIT_INTERNAL_ERROR 254
161 #define EXIT_DEADLOCK 253
162 #define EXIT_INTERRUPTED 252
163 #define EXIT_HEAPOVERFLOW 251
164 #define EXIT_KILLED 250
166 /* -----------------------------------------------------------------------------
167 Miscellaneous garbage
168 -------------------------------------------------------------------------- */
170 /* declarations for runtime flags/values */
171 #define MAX_RTS_ARGS 32
173 /* -----------------------------------------------------------------------------
174 Assertions and Debuggery
175 -------------------------------------------------------------------------- */
177 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
179 /* -----------------------------------------------------------------------------
180 Assertions and Debuggery
181 -------------------------------------------------------------------------- */
184 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
186 #define IF_DEBUG(c,s) doNothing()
190 #define DEBUG_ONLY(s) s
192 #define DEBUG_ONLY(s) doNothing()
195 #if defined(GRAN) && defined(DEBUG)
196 #define IF_GRAN_DEBUG(c,s) if (RtsFlags.GranFlags.Debug.c) { s; }
198 #define IF_GRAN_DEBUG(c,s) doNothing()
201 #if defined(PAR) && defined(DEBUG)
202 #define IF_PAR_DEBUG(c,s) if (RtsFlags.ParFlags.Debug.c) { s; }
204 #define IF_PAR_DEBUG(c,s) doNothing()
207 /* -----------------------------------------------------------------------------
208 Useful macros and inline functions
209 -------------------------------------------------------------------------- */
211 #if defined(__GNUC__)
212 #define SUPPORTS_TYPEOF
215 #if defined(SUPPORTS_TYPEOF)
216 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
217 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
219 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
220 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
223 /* -------------------------------------------------------------------------- */