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