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