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