[project @ 2005-05-10 13:25:41 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_HOST_OS
38 #define __MSVCRT__ 1
39 #endif
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 (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 /* -----------------------------------------------------------------------------
78    Include everything STG-ish
79    -------------------------------------------------------------------------- */
80
81 /* System headers: stdlib.h is eeded so that we can use NULL.  It must
82  * come after MachRegs.h, because stdlib.h might define some inline
83  * functions which may only be defined after register variables have
84  * been declared.
85  */
86 #include <stdlib.h>
87
88 /* Global constaints */
89 #include "Constants.h"
90
91 /* Profiling information */
92 #include "StgProf.h"
93 #include "StgLdvProf.h"
94
95 /* Storage format definitions */
96 #include "StgFun.h"
97 #include "Closures.h"
98 #include "Liveness.h"
99 #include "ClosureTypes.h"
100 #include "InfoTables.h"
101 #include "TSO.h"
102
103 /* Info tables, closures & code fragments defined in the RTS */
104 #include "StgMiscClosures.h"
105
106 /* Simulated-parallel information */
107 #include "GranSim.h"
108
109 /* Parallel information */
110 #include "Parallel.h"
111
112 /* STG/Optimised-C related stuff */
113 #include "Block.h"
114
115 /* GNU mp library */
116 #include "gmp.h"
117
118 /* Macros for STG/C code */
119 #include "ClosureMacros.h"
120 #include "StgTicky.h"
121 #include "Stable.h"
122
123 /* Runtime-system hooks */
124 #include "Hooks.h"
125 #include "RtsMessages.h"
126
127 #include "ieee-flpt.h"
128
129 #include "Signals.h"
130
131 /* Misc stuff without a home */
132 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
133 DLL_IMPORT_RTS extern int    prog_argc;
134 DLL_IMPORT_RTS extern char  *prog_name;
135
136 extern void stackOverflow(void);
137
138 extern void      __decodeDouble (MP_INT *man, I_ *_exp, StgDouble dbl);
139 extern void      __decodeFloat  (MP_INT *man, I_ *_exp, StgFloat flt);
140
141 #if defined(WANT_DOTNET_SUPPORT)
142 #include "DNInvoke.h"
143 #endif
144
145 /* Initialising the whole adjustor thunk machinery. */
146 extern void initAdjustor(void);
147
148 extern void stg_exit(int n) GNU_ATTRIBUTE(__noreturn__);
149
150 /* -----------------------------------------------------------------------------
151    RTS Exit codes
152    -------------------------------------------------------------------------- */
153
154 /* 255 is allegedly used by dynamic linkers to report linking failure */
155 #define EXIT_INTERNAL_ERROR 254
156 #define EXIT_DEADLOCK       253
157 #define EXIT_INTERRUPTED    252
158 #define EXIT_HEAPOVERFLOW   251
159 #define EXIT_KILLED         250
160
161 /* -----------------------------------------------------------------------------
162    Miscellaneous garbage
163    -------------------------------------------------------------------------- */
164
165 /* declarations for runtime flags/values */
166 #define MAX_RTS_ARGS 32
167
168 /* -----------------------------------------------------------------------------
169    Assertions and Debuggery
170    -------------------------------------------------------------------------- */
171
172 #define IF_RTSFLAGS(c,s)  if (RtsFlags.c) { s; }
173
174 /* -----------------------------------------------------------------------------
175    Assertions and Debuggery
176    -------------------------------------------------------------------------- */
177
178 #ifdef DEBUG
179 #define IF_DEBUG(c,s)  if (RtsFlags.DebugFlags.c) { s; }
180 #else
181 #define IF_DEBUG(c,s)  doNothing()
182 #endif
183
184 #ifdef DEBUG
185 #define DEBUG_ONLY(s) s
186 #else
187 #define DEBUG_ONLY(s) doNothing()
188 #endif
189
190 #if defined(GRAN) && defined(DEBUG)
191 #define IF_GRAN_DEBUG(c,s)  if (RtsFlags.GranFlags.Debug.c) { s; }
192 #else
193 #define IF_GRAN_DEBUG(c,s)  doNothing()
194 #endif
195
196 #if defined(PAR) && defined(DEBUG)
197 #define IF_PAR_DEBUG(c,s)  if (RtsFlags.ParFlags.Debug.c) { s; }
198 #else
199 #define IF_PAR_DEBUG(c,s)  doNothing()
200 #endif
201
202 /* -----------------------------------------------------------------------------
203    Useful macros and inline functions
204    -------------------------------------------------------------------------- */
205
206 #if defined(__GNUC__)
207 #define SUPPORTS_TYPEOF
208 #endif
209
210 #if defined(SUPPORTS_TYPEOF)
211 #define stg_min(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _a : _b; })
212 #define stg_max(a,b) ({typeof(a) _a = (a), _b = (b); _a <= _b ? _b : _a; })
213 #else
214 #define stg_min(a,b) ((a) <= (b) ? (a) : (b))
215 #define stg_max(a,b) ((a) <= (b) ? (b) : (a))
216 #endif
217
218 /* -------------------------------------------------------------------------- */
219
220 #ifdef __cplusplus
221 }
222 #endif
223
224 #endif /* RTS_H */