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