[project @ 2004-08-13 13:04:50 by simonmar]
[ghc-hetmet.git] / ghc / includes / Rts.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Rts.h,v 1.24 2004/08/13 13:09:27 simonmar Exp $
3  *
4  * (c) The GHC Team, 1998-1999
5  *
6  * Top-level include file for the RTS itself
7  *
8  * ---------------------------------------------------------------------------*/
9
10 #ifndef RTS_H
11 #define RTS_H
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 #ifndef IN_STG_CODE
18 #define IN_STG_CODE 0
19 #endif
20 #include "Stg.h"
21
22 #include "RtsTypes.h"
23
24 #if __GNUC__ >= 3
25 /* Assume that a flexible array member at the end of a struct
26  * can be defined thus: T arr[]; */
27 #define FLEXIBLE_ARRAY
28 #else
29 /* Assume that it must be defined thus: T arr[0]; */
30 #define FLEXIBLE_ARRAY 0
31 #endif
32
33 #if defined(SMP) || defined(THREADED_RTS)
34 #define RTS_SUPPORTS_THREADS 1
35 #endif
36
37 /* Fix for mingw stat problem (done here so it's early enough) */
38 #ifdef mingw32_TARGET_OS
39 #define __MSVCRT__ 1
40 #endif
41
42 #if defined(__GNUC__)
43 #define GNU_ATTRIBUTE(at) __attribute__((at))
44 #else
45 #define GNU_ATTRIBUTE(at)
46 #endif
47
48 #if __GNUC__ >= 3 
49 #define GNUC3_ATTRIBUTE(at) __attribute__((at))
50 #else
51 #define GNUC3_ATTRIBUTE(at)
52 #endif
53
54 /* 
55  * Empty structures isn't supported by all, so to define
56  * empty structures, please protect the defn with an
57  * #if SUPPORTS_EMPTY_STRUCTS. Similarly for use,
58  * employ the macro MAYBE_EMPTY_STRUCT():
59  *
60  *     MAYBE_EMPTY_STRUCT(structFoo, fieldName);
61  */
62 #if SUPPORTS_EMPTY_STRUCTS
63 # define MAYBE_EMPTY_STRUCT(a,b) a b;
64 #else
65 # define MAYBE_EMPTY_STRUCT(a,b) /* empty */
66 #endif
67
68 /*
69  * We often want to know the size of something in units of an
70  * StgWord... (rounded up, of course!)
71  */
72 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
73
74 /* 
75  * It's nice to be able to grep for casts
76  */
77 #define stgCast(ty,e) ((ty)(e))
78
79 /* -----------------------------------------------------------------------------
80    Assertions and Debuggery
81    -------------------------------------------------------------------------- */
82
83 #ifndef DEBUG
84 #define ASSERT(predicate) /* nothing */
85 #else
86
87 void _stgAssert (char *, unsigned int);
88
89 #define ASSERT(predicate)                       \
90         if (predicate)                          \
91             /*null*/;                           \
92         else                                    \
93             _stgAssert(__FILE__, __LINE__)
94 #endif /* DEBUG */
95
96 /* 
97  * Use this on the RHS of macros which expand to nothing
98  * to make sure that the macro can be used in a context which
99  * demands a non-empty statement.
100  */
101
102 #define doNothing() do { } while (0)
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
139 /* STG/Optimised-C related stuff */
140 #include "SMP.h"
141 #include "Block.h"
142
143 #ifdef SMP
144 #include <pthread.h>
145 #endif
146
147 /* GNU mp library */
148 #include "gmp.h"
149
150 /* Macros for STG/C code */
151 #include "ClosureMacros.h"
152 #include "StgTicky.h"
153 #include "Stable.h"
154
155 /* Runtime-system hooks */
156 #include "Hooks.h"
157
158 #include "ieee-flpt.h"
159
160 #include "Signals.h"
161
162 /* Misc stuff without a home */
163 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
164 DLL_IMPORT_RTS extern int    prog_argc;
165 DLL_IMPORT_RTS extern char  *prog_name;
166
167 extern void stackOverflow(void);
168
169 extern void      __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
170 extern void      __decodeFloat  (MP_INT *man, I_ *_exp, StgFloat flt);
171
172 #if defined(WANT_DOTNET_SUPPORT)
173 #include "DNInvoke.h"
174 #endif
175
176 /* Creating and destroying an adjustor thunk and initialising the whole
177    adjustor thunk machinery. I cannot make myself create a separate .h file
178    for these three (sof.) 
179    
180 */
181 extern void*   createAdjustor(int cconv, StgStablePtr hptr, StgFunPtr wptr);
182 extern void    freeHaskellFunctionPtr(void* ptr);
183 extern rtsBool initAdjustor(void);
184
185 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
186
187 /* -----------------------------------------------------------------------------
188    RTS Exit codes
189    -------------------------------------------------------------------------- */
190
191 /* 255 is allegedly used by dynamic linkers to report linking failure */
192 #define EXIT_INTERNAL_ERROR 254
193 #define EXIT_DEADLOCK       253
194 #define EXIT_INTERRUPTED    252
195 #define EXIT_HEAPOVERFLOW   251
196 #define EXIT_KILLED         250
197
198 /* -----------------------------------------------------------------------------
199    Miscellaneous garbage
200    -------------------------------------------------------------------------- */
201
202 /* declarations for runtime flags/values */
203 #define MAX_RTS_ARGS 32
204
205 #ifdef _WIN32
206 /* On the yucky side..suppress -Wmissing-declarations warnings when
207  * including <windows.h>
208  */
209 extern void* GetCurrentFiber ( void );
210 extern void* GetFiberData ( void );
211 #endif
212
213 /* -----------------------------------------------------------------------------
214    Assertions and Debuggery
215    -------------------------------------------------------------------------- */
216
217 #define IF_RTSFLAGS(c,s)  if (RtsFlags.c) { s; }
218
219 /* -----------------------------------------------------------------------------
220    Assertions and Debuggery
221    -------------------------------------------------------------------------- */
222
223 #ifdef DEBUG
224 #define IF_DEBUG(c,s)  if (RtsFlags.DebugFlags.c) { s; }
225 #else
226 #define IF_DEBUG(c,s)  doNothing()
227 #endif
228
229 #ifdef DEBUG
230 #define DEBUG_ONLY(s) s
231 #else
232 #define DEBUG_ONLY(s) doNothing()
233 #endif
234
235 #if defined(GRAN) && defined(DEBUG)
236 #define IF_GRAN_DEBUG(c,s)  if (RtsFlags.GranFlags.Debug.c) { s; }
237 #else
238 #define IF_GRAN_DEBUG(c,s)  doNothing()
239 #endif
240
241 #if defined(PAR) && defined(DEBUG)
242 #define IF_PAR_DEBUG(c,s)  if (RtsFlags.ParFlags.Debug.c) { s; }
243 #else
244 #define IF_PAR_DEBUG(c,s)  doNothing()
245 #endif
246
247 /* -----------------------------------------------------------------------------
248    Attributes
249    -------------------------------------------------------------------------- */
250
251 #ifdef __GNUC__     /* Avoid spurious warnings                             */
252 #if (__GNUC__ == 2 && __GNUC_MINOR__ >= 7) || __GNUC__ >= 3
253 #define STG_NORETURN  __attribute__ ((noreturn))
254 #define STG_UNUSED    __attribute__ ((unused))
255 #else
256 #define STG_NORETURN  
257 #define STG_UNUSED
258 #endif
259 #else
260 #define STG_NORETURN  
261 #define STG_UNUSED
262 #endif
263
264 #if defined(__GNUC__)
265 #define SUPPORTS_TYPEOF
266 #endif
267
268 /* -----------------------------------------------------------------------------
269    Useful macros and inline functions
270    -------------------------------------------------------------------------- */
271
272 #if defined(SUPPORTS_TYPEOF)
273 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
274 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
275 #else
276 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
277 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
278 #endif
279
280 /* -------------------------------------------------------------------------- */
281
282 #ifdef __cplusplus
283 }
284 #endif
285
286 #endif /* RTS_H */