don't make -ddump-if-trace imply -no-recomp
[ghc-hetmet.git] / includes / Rts.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-2004
4  *
5  * Top-level include file for the RTS itself
6  *
7  * ---------------------------------------------------------------------------*/
8
9 #ifndef RTS_H
10 #define RTS_H
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 #ifndef IN_STG_CODE
17 #define IN_STG_CODE 0
18 #endif
19 #include "Stg.h"
20
21 // ToDo: move RtsExternal stuff elsewhere
22 #include "RtsExternal.h"
23
24 // Turn off inlining when debugging - it obfuscates things
25 #ifdef DEBUG
26 # undef  STATIC_INLINE
27 # define STATIC_INLINE static
28 #endif
29
30 #include "RtsTypes.h"
31
32 #if __GNUC__ >= 3
33 /* Assume that a flexible array member at the end of a struct
34  * can be defined thus: T arr[]; */
35 #define FLEXIBLE_ARRAY
36 #else
37 /* Assume that it must be defined thus: T arr[0]; */
38 #define FLEXIBLE_ARRAY 0
39 #endif
40
41 /* Fix for mingw stat problem (done here so it's early enough) */
42 #ifdef mingw32_HOST_OS
43 #define __MSVCRT__ 1
44 #endif
45
46 /* Needed to get the macro version of errno on some OSs, and also to
47    get prototypes for the _r versions of C library functions. */
48 #define _REENTRANT 1
49
50 /*
51  * We often want to know the size of something in units of an
52  * StgWord... (rounded up, of course!)
53  */
54 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
55
56 /* 
57  * It's nice to be able to grep for casts
58  */
59 #define stgCast(ty,e) ((ty)(e))
60
61 /* -----------------------------------------------------------------------------
62    Assertions and Debuggery
63    -------------------------------------------------------------------------- */
64
65 #ifndef DEBUG
66 #define ASSERT(predicate) /* nothing */
67 #else
68
69 extern void _assertFail (const char *, unsigned int);
70
71 #define ASSERT(predicate)                       \
72         if (predicate)                          \
73             /*null*/;                           \
74         else                                    \
75             _assertFail(__FILE__, __LINE__)
76 #endif /* DEBUG */
77
78 /* 
79  * Use this on the RHS of macros which expand to nothing
80  * to make sure that the macro can be used in a context which
81  * demands a non-empty statement.
82  */
83
84 #define doNothing() do { } while (0)
85
86 #ifdef DEBUG
87 #define USED_IF_DEBUG
88 #define USED_IF_NOT_DEBUG STG_UNUSED
89 #else
90 #define USED_IF_DEBUG STG_UNUSED
91 #define USED_IF_NOT_DEBUG
92 #endif
93
94 #ifdef THREADED_RTS
95 #define USED_IF_THREADS
96 #define USED_IF_NOT_THREADS STG_UNUSED
97 #else
98 #define USED_IF_THREADS STG_UNUSED
99 #define USED_IF_NOT_THREADS
100 #endif
101
102 /*
103  * Getting printf formats right for platform-dependent typedefs
104  */
105 #if SIZEOF_LONG == 8
106 #define FMT_Word64 "lu"
107 #define FMT_Int64  "ld"
108 #else
109 #define FMT_Word64 "llu"
110 #define FMT_Int64  "lld"
111 #endif
112
113 /*
114  * Macros for untagging and retagging closure pointers
115  * For more information look at the comments in Cmm.h
116  */
117
118 static inline StgWord
119 GET_CLOSURE_TAG(StgClosure * p)
120 {
121     return (StgWord)p & TAG_MASK;
122 }
123
124 static inline StgClosure *
125 UNTAG_CLOSURE(StgClosure * p)
126 {
127     return (StgClosure*)((StgWord)p & ~TAG_MASK);
128 }
129
130 static inline StgClosure *
131 TAG_CLOSURE(StgWord tag,StgClosure * p)
132 {
133     return (StgClosure*)((StgWord)p | tag);
134 }
135
136 /* -----------------------------------------------------------------------------
137    Include everything STG-ish
138    -------------------------------------------------------------------------- */
139
140 /* System headers: stdlib.h is eeded so that we can use NULL.  It must
141  * come after MachRegs.h, because stdlib.h might define some inline
142  * functions which may only be defined after register variables have
143  * been declared.
144  */
145 #include <stdlib.h>
146
147 /* Global constaints */
148 #include "Constants.h"
149
150 /* Profiling information */
151 #include "StgProf.h"
152 #include "StgLdvProf.h"
153
154 /* Storage format definitions */
155 #include "StgFun.h"
156 #include "Closures.h"
157 #include "Liveness.h"
158 #include "ClosureTypes.h"
159 #include "InfoTables.h"
160 #include "TSO.h"
161
162 /* Info tables, closures & code fragments defined in the RTS */
163 #include "StgMiscClosures.h"
164
165 /* Simulated-parallel information */
166 #include "GranSim.h"
167
168 /* Parallel information */
169 #include "Parallel.h"
170 #include "OSThreads.h"
171 #include "SMPClosureOps.h"
172 #include "SpinLock.h"
173
174 /* GNU mp library */
175 #if defined(HAVE_FRAMEWORK_GMP)
176 #include <GMP/gmp.h>
177 #else
178 #include "gmp.h"
179 #endif
180
181 /* Macros for STG/C code */
182 #include "Block.h"
183 #include "ClosureMacros.h"
184
185   /* Ticky-ticky counters */
186 #include "TickyCounters.h"
187
188 /* Runtime-system hooks */
189 #include "Hooks.h"
190 #include "RtsMessages.h"
191
192 /* for StablePtr/getStablePtr/deRefStablePtr */
193 #include "Storage.h"
194 #include "Stable.h"
195
196 #include "ieee-flpt.h"
197
198 #include "Signals.h"
199
200 /* Misc stuff without a home */
201 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
202 DLL_IMPORT_RTS extern int    prog_argc;
203 DLL_IMPORT_RTS extern char  *prog_name;
204
205 extern void stackOverflow(void);
206
207 extern void      __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
208 extern void      __decodeFloat  (MP_INT *man, I_ *_exp, StgFloat flt);
209 extern void      __decodeDouble_2Int (I_ *man_high, I_ *man_low, I_ *exp, StgDouble dbl);
210 extern void      __decodeFloat_Int (I_ *man, I_ *exp, StgFloat flt);
211
212 #if defined(WANT_DOTNET_SUPPORT)
213 #include "DNInvoke.h"
214 #endif
215
216 /* Initialising the whole adjustor thunk machinery. */
217 extern void initAdjustor(void);
218
219 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
220
221 /* -----------------------------------------------------------------------------
222    RTS Exit codes
223    -------------------------------------------------------------------------- */
224
225 /* 255 is allegedly used by dynamic linkers to report linking failure */
226 #define EXIT_INTERNAL_ERROR 254
227 #define EXIT_DEADLOCK       253
228 #define EXIT_INTERRUPTED    252
229 #define EXIT_HEAPOVERFLOW   251
230 #define EXIT_KILLED         250
231
232 /* -----------------------------------------------------------------------------
233    Miscellaneous garbage
234    -------------------------------------------------------------------------- */
235
236 /* declarations for runtime flags/values */
237 #define MAX_RTS_ARGS 32
238
239 #ifdef DEBUG
240 #define TICK_VAR(arity) \
241   extern StgInt SLOW_CALLS_##arity; \
242   extern StgInt RIGHT_ARITY_##arity; \
243   extern StgInt TAGGED_PTR_##arity;
244
245 #define TICK_VAR_INI(arity) \
246   StgInt SLOW_CALLS_##arity = 1; \
247   StgInt RIGHT_ARITY_##arity = 1; \
248   StgInt TAGGED_PTR_##arity = 0;
249
250 extern StgInt TOTAL_CALLS;
251
252 TICK_VAR(1)
253 TICK_VAR(2)
254 #endif
255
256 /* -----------------------------------------------------------------------------
257    Assertions and Debuggery
258    -------------------------------------------------------------------------- */
259
260 #define IF_RTSFLAGS(c,s)  if (RtsFlags.c) { s; }
261
262 /* -----------------------------------------------------------------------------
263    Assertions and Debuggery
264    -------------------------------------------------------------------------- */
265
266 #ifdef DEBUG
267 #if IN_STG_CODE
268 #define IF_DEBUG(c,s)  if (RtsFlags[0].DebugFlags.c) { s; }
269 #else
270 #define IF_DEBUG(c,s)  if (RtsFlags.DebugFlags.c) { s; }
271 #endif
272 #else
273 #define IF_DEBUG(c,s)  doNothing()
274 #endif
275
276 #ifdef DEBUG
277 #define DEBUG_ONLY(s) s
278 #else
279 #define DEBUG_ONLY(s) doNothing()
280 #endif
281
282 #if defined(GRAN) && defined(DEBUG)
283 #define IF_GRAN_DEBUG(c,s)  if (RtsFlags.GranFlags.Debug.c) { s; }
284 #else
285 #define IF_GRAN_DEBUG(c,s)  doNothing()
286 #endif
287
288 #if defined(PAR) && defined(DEBUG)
289 #define IF_PAR_DEBUG(c,s)  if (RtsFlags.ParFlags.Debug.c) { s; }
290 #else
291 #define IF_PAR_DEBUG(c,s)  doNothing()
292 #endif
293
294 /* -----------------------------------------------------------------------------
295    Useful macros and inline functions
296    -------------------------------------------------------------------------- */
297
298 #if defined(__GNUC__)
299 #define SUPPORTS_TYPEOF
300 #endif
301
302 #if defined(SUPPORTS_TYPEOF)
303 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
304 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
305 #else
306 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
307 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
308 #endif
309
310 /* -------------------------------------------------------------------------- */
311
312 #ifdef __cplusplus
313 }
314 #endif
315
316
317 /* krc: I put this here because I don't think
318    it needs to be visible externally.
319    It used to be in StgTicky.h, but I got rid
320    of that. */
321
322 /* -----------------------------------------------------------------------------
323    The StgEntCounter type - needed regardless of TICKY_TICKY
324    -------------------------------------------------------------------------- */
325
326 typedef struct _StgEntCounter {
327   /* Using StgWord for everything, becuase both the C and asm code
328      generators make trouble if you try to pack things tighter */
329     StgWord     registeredp;    /* 0 == no, 1 == yes */
330     StgInt      arity;          /* arity (static info) */
331     StgInt      stk_args;       /* # of args off stack */
332                                 /* (rest of args are in registers) */
333     char        *str;           /* name of the thing */
334     char        *arg_kinds;     /* info about the args types */
335     StgInt      entry_count;    /* Trips to fast entry code */
336     StgInt      allocs;         /* number of allocations by this fun */
337     struct _StgEntCounter *link;/* link to chain them all together */
338 } StgEntCounter;
339
340
341 #endif /* RTS_H */