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