fix warnings
[ghc.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 #include "RtsTypes.h"
22
23 #if __GNUC__ >= 3
24 /* Assume that a flexible array member at the end of a struct
25 * can be defined thus: T arr[]; */
26 #define FLEXIBLE_ARRAY
27 #else
28 /* Assume that it must be defined thus: T arr[0]; */
29 #define FLEXIBLE_ARRAY 0
30 #endif
31
32 /* Fix for mingw stat problem (done here so it's early enough) */
33 #ifdef mingw32_HOST_OS
34 #define __MSVCRT__ 1
35 #endif
36
37 /* Needed to get the macro version of errno on some OSs, and also to
38 get prototypes for the _r versions of C library functions. */
39 #define _REENTRANT 1
40
41 /*
42 * We often want to know the size of something in units of an
43 * StgWord... (rounded up, of course!)
44 */
45 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
46
47 /*
48 * It's nice to be able to grep for casts
49 */
50 #define stgCast(ty,e) ((ty)(e))
51
52 /* -----------------------------------------------------------------------------
53 Assertions and Debuggery
54 -------------------------------------------------------------------------- */
55
56 #ifndef DEBUG
57 #define ASSERT(predicate) /* nothing */
58 #else
59
60 extern void _assertFail (const char *, unsigned int);
61
62 #define ASSERT(predicate) \
63 if (predicate) \
64 /*null*/; \
65 else \
66 _assertFail(__FILE__, __LINE__)
67 #endif /* DEBUG */
68
69 /*
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.
73 */
74
75 #define doNothing() do { } while (0)
76
77 #ifdef DEBUG
78 #define USED_IF_DEBUG
79 #define USED_IF_NOT_DEBUG STG_UNUSED
80 #else
81 #define USED_IF_DEBUG STG_UNUSED
82 #define USED_IF_NOT_DEBUG
83 #endif
84
85 #ifdef THREADED_RTS
86 #define USED_IF_THREADS
87 #define USED_IF_NOT_THREADS STG_UNUSED
88 #else
89 #define USED_IF_THREADS STG_UNUSED
90 #define USED_IF_NOT_THREADS
91 #endif
92
93 /*
94 * Getting printf formats right for platform-dependent typedefs
95 */
96 #if SIZEOF_LONG == 8
97 #define FMT_Word64 "lu"
98 #define FMT_Int64 "ld"
99 #else
100 #define FMT_Word64 "llu"
101 #define FMT_Int64 "lld"
102 #endif
103
104 /* -----------------------------------------------------------------------------
105 Include everything STG-ish
106 -------------------------------------------------------------------------- */
107
108 /* System headers: stdlib.h is eeded so that we can use NULL. It must
109 * come after MachRegs.h, because stdlib.h might define some inline
110 * functions which may only be defined after register variables have
111 * been declared.
112 */
113 #include <stdlib.h>
114
115 /* Global constaints */
116 #include "Constants.h"
117
118 /* Profiling information */
119 #include "StgProf.h"
120 #include "StgLdvProf.h"
121
122 /* Storage format definitions */
123 #include "StgFun.h"
124 #include "Closures.h"
125 #include "Liveness.h"
126 #include "ClosureTypes.h"
127 #include "InfoTables.h"
128 #include "TSO.h"
129
130 /* Info tables, closures & code fragments defined in the RTS */
131 #include "StgMiscClosures.h"
132
133 /* Simulated-parallel information */
134 #include "GranSim.h"
135
136 /* Parallel information */
137 #include "Parallel.h"
138 #include "OSThreads.h"
139 #include "SMP.h"
140
141 /* STG/Optimised-C related stuff */
142 #include "Block.h"
143
144 /* GNU mp library */
145 #include "gmp.h"
146
147 /* Macros for STG/C code */
148 #include "ClosureMacros.h"
149 #include "StgTicky.h"
150 #include "Stable.h"
151
152 /* Runtime-system hooks */
153 #include "Hooks.h"
154 #include "RtsMessages.h"
155
156 #include "ieee-flpt.h"
157
158 #include "Signals.h"
159
160 /* Misc stuff without a home */
161 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
162 DLL_IMPORT_RTS extern int prog_argc;
163 DLL_IMPORT_RTS extern char *prog_name;
164
165 extern void stackOverflow(void);
166
167 extern void __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
168 extern void __decodeFloat (MP_INT *man, I_ *_exp, StgFloat flt);
169
170 #if defined(WANT_DOTNET_SUPPORT)
171 #include "DNInvoke.h"
172 #endif
173
174 /* Initialising the whole adjustor thunk machinery. */
175 extern void initAdjustor(void);
176
177 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
178
179 /* -----------------------------------------------------------------------------
180 RTS Exit codes
181 -------------------------------------------------------------------------- */
182
183 /* 255 is allegedly used by dynamic linkers to report linking failure */
184 #define EXIT_INTERNAL_ERROR 254
185 #define EXIT_DEADLOCK 253
186 #define EXIT_INTERRUPTED 252
187 #define EXIT_HEAPOVERFLOW 251
188 #define EXIT_KILLED 250
189
190 /* -----------------------------------------------------------------------------
191 Miscellaneous garbage
192 -------------------------------------------------------------------------- */
193
194 /* declarations for runtime flags/values */
195 #define MAX_RTS_ARGS 32
196
197 /* -----------------------------------------------------------------------------
198 Assertions and Debuggery
199 -------------------------------------------------------------------------- */
200
201 #define IF_RTSFLAGS(c,s) if (RtsFlags.c) { s; }
202
203 /* -----------------------------------------------------------------------------
204 Assertions and Debuggery
205 -------------------------------------------------------------------------- */
206
207 #ifdef DEBUG
208 #define IF_DEBUG(c,s) if (RtsFlags.DebugFlags.c) { s; }
209 #else
210 #define IF_DEBUG(c,s) doNothing()
211 #endif
212
213 #ifdef DEBUG
214 #define DEBUG_ONLY(s) s
215 #else
216 #define DEBUG_ONLY(s) doNothing()
217 #endif
218
219 #if defined(GRAN) && defined(DEBUG)
220 #define IF_GRAN_DEBUG(c,s) if (RtsFlags.GranFlags.Debug.c) { s; }
221 #else
222 #define IF_GRAN_DEBUG(c,s) doNothing()
223 #endif
224
225 #if defined(PAR) && defined(DEBUG)
226 #define IF_PAR_DEBUG(c,s) if (RtsFlags.ParFlags.Debug.c) { s; }
227 #else
228 #define IF_PAR_DEBUG(c,s) doNothing()
229 #endif
230
231 /* -----------------------------------------------------------------------------
232 Useful macros and inline functions
233 -------------------------------------------------------------------------- */
234
235 #if defined(__GNUC__)
236 #define SUPPORTS_TYPEOF
237 #endif
238
239 #if defined(SUPPORTS_TYPEOF)
240 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
241 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
242 #else
243 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
244 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
245 #endif
246
247 /* -------------------------------------------------------------------------- */
248
249 #ifdef __cplusplus
250 }
251 #endif
252
253 #endif /* RTS_H */