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