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 #define GNU_ATTRIBUTE(at) __attribute__((at))
44 #define GNU_ATTRIBUTE(at)
48 #define GNUC3_ATTRIBUTE(at) __attribute__((at))
50 #define GNUC3_ATTRIBUTE(at)
53 #define STG_UNUSED GNUC3_ATTRIBUTE(__unused__)
56 * We often want to know the size of something in units of an
57 * StgWord... (rounded up, of course!)
59 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
62 * It's nice to be able to grep for casts
64 #define stgCast(ty,e) ((ty)(e))
66 /* -----------------------------------------------------------------------------
67 Assertions and Debuggery
68 -------------------------------------------------------------------------- */
71 #define ASSERT(predicate) /* nothing */
74 void _stgAssert (char *, unsigned int);
76 #define ASSERT(predicate) \
80 _stgAssert(__FILE__, __LINE__)
84 * Use this on the RHS of macros which expand to nothing
85 * to make sure that the macro can be used in a context which
86 * demands a non-empty statement.
89 #define doNothing() do { } while (0)
91 /* -----------------------------------------------------------------------------
92 Include everything STG-ish
93 -------------------------------------------------------------------------- */
95 /* System headers: stdlib.h is eeded so that we can use NULL. It must
96 * come after MachRegs.h, because stdlib.h might define some inline
97 * functions which may only be defined after register variables have
102 /* Global constaints */
103 #include "Constants.h"
105 /* Profiling information */
107 #include "StgLdvProf.h"
109 /* Storage format definitions */
111 #include "Closures.h"
112 #include "Liveness.h"
113 #include "ClosureTypes.h"
114 #include "InfoTables.h"
117 /* Info tables, closures & code fragments defined in the RTS */
118 #include "StgMiscClosures.h"
120 /* Simulated-parallel information */
123 /* Parallel information */
124 #include "Parallel.h"
126 /* STG/Optimised-C related stuff */
137 /* Macros for STG/C code */
138 #include "ClosureMacros.h"
139 #include "StgTicky.h"
142 /* Runtime-system hooks */
144 #include "RtsMessages.h"
146 #include "ieee-flpt.h"
150 /* Misc stuff without a home */
151 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
152 DLL_IMPORT_RTS extern int prog_argc;
153 DLL_IMPORT_RTS extern char *prog_name;
155 extern void stackOverflow(void);
157 extern void __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
158 extern void __decodeFloat (MP_INT *man, I_ *_exp, StgFloat flt);
160 #if defined(WANT_DOTNET_SUPPORT)
161 #include "DNInvoke.h"
164 /* Initialising the whole adjustor thunk machinery. */
165 extern void initAdjustor(void);
167 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
169 /* -----------------------------------------------------------------------------
171 -------------------------------------------------------------------------- */
173 /* 255 is allegedly used by dynamic linkers to report linking failure */
174 #define EXIT_INTERNAL_ERROR 254
175 #define EXIT_DEADLOCK 253
176 #define EXIT_INTERRUPTED 252
177 #define EXIT_HEAPOVERFLOW 251
178 #define EXIT_KILLED 250
180 /* -----------------------------------------------------------------------------
181 Miscellaneous garbage
182 -------------------------------------------------------------------------- */
184 /* declarations for runtime flags/values */
185 #define MAX_RTS_ARGS 32
187 /* -----------------------------------------------------------------------------
188 Assertions and Debuggery
189 -------------------------------------------------------------------------- */
191 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
193 /* -----------------------------------------------------------------------------
194 Assertions and Debuggery
195 -------------------------------------------------------------------------- */
198 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
200 #define IF_DEBUG(c,s) doNothing()
204 #define DEBUG_ONLY(s) s
206 #define DEBUG_ONLY(s) doNothing()
209 #if defined(GRAN) && defined(DEBUG)
210 #define IF_GRAN_DEBUG(c,s) if (RtsFlags.GranFlags.Debug.c) { s; }
212 #define IF_GRAN_DEBUG(c,s) doNothing()
215 #if defined(PAR) && defined(DEBUG)
216 #define IF_PAR_DEBUG(c,s) if (RtsFlags.ParFlags.Debug.c) { s; }
218 #define IF_PAR_DEBUG(c,s) doNothing()
221 /* -----------------------------------------------------------------------------
222 Useful macros and inline functions
223 -------------------------------------------------------------------------- */
225 #if defined(__GNUC__)
226 #define SUPPORTS_TYPEOF
229 #if defined(SUPPORTS_TYPEOF)
230 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
231 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
233 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
234 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
237 /* -------------------------------------------------------------------------- */