dd41d37f2c809483875c06c7d682858ab2b00ad1
[ghc-hetmet.git] / ghc / includes / Stg.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Stg.h,v 1.62 2004/03/23 10:03:18 simonmar Exp $
3  *
4  * (c) The GHC Team, 1998-1999
5  *
6  * Top-level include file for everything STG-ish.  
7  *
8  * This file is included *automatically* by all .hc files.
9  *
10  * NOTE: always include Stg.h *before* any other headers, because we
11  * define some register variables which must be done before any inline
12  * functions are defined (some system headers have been known to
13  * define the odd inline function).
14  *
15  * ---------------------------------------------------------------------------*/
16
17 #ifndef STG_H
18 #define STG_H
19
20
21 /* If we include "Stg.h" directly, we're in STG code, and we therefore
22  * get all the global register variables, macros etc. that go along
23  * with that.  If "Stg.h" is included via "Rts.h", we're assumed to
24  * be in vanilla C.
25  */
26 #ifndef IN_STG_CODE
27 # define IN_STG_CODE 1
28 #endif
29
30 #if IN_STG_CODE == 0
31 # ifndef NO_REGS
32 #  define NO_REGS                       /* don't define fixed registers */
33 # endif
34 #endif
35
36 /* Configuration */
37 #include "config.h"
38
39 /* This needs to be up near the top as the register line on alpha needs
40  * to be before all procedures */
41 #include "TailCalls.h"
42
43 #if __GNUC__ >= 3
44 /* Assume that a flexible array member at the end of a struct
45  * can be defined thus: T arr[]; */
46 #define FLEXIBLE_ARRAY
47 #else
48 /* Assume that it must be defined thus: T arr[0]; */
49 #define FLEXIBLE_ARRAY 0
50 #endif
51
52 #if defined(SMP) || defined(THREADED_RTS)
53 #define RTS_SUPPORTS_THREADS 1
54 #endif
55
56 /* Some macros to handle DLLing (Win32 only at the moment). */
57 #include "StgDLL.h"
58
59 /* Fix for mingw stat problem (done here so it's early enough) */
60 #ifdef mingw32_TARGET_OS
61 #define __MSVCRT__ 1
62 #endif
63
64 /* Turn lazy blackholing and eager blackholing on/off.
65  *
66  * Using eager blackholing makes things easier to debug because
67  * the blackholes are more predictable - but it's slower and less sexy.
68  *
69  * For now, do lazy and not eager.
70  */
71
72 /* TICKY_TICKY needs EAGER_BLACKHOLING to verify no double-entries of
73  * single-entry thunks.
74  *
75  * SMP needs EAGER_BLACKHOLING because it has to lock thunks
76  * synchronously, in case another thread is trying to evaluate the
77  * same thunk simultaneously.
78  */
79 #if defined(SMP) || defined(TICKY_TICKY)
80 #  define EAGER_BLACKHOLING
81 #else
82 #  define LAZY_BLACKHOLING
83 #endif
84
85 #if defined(__GNUC__)
86 #define GNU_ATTRIBUTE(at) __attribute__((at))
87 #else
88 #define GNU_ATTRIBUTE(at)
89 #endif
90
91 #if __GNUC__ >= 3 
92 #define GNUC3_ATTRIBUTE(at) __attribute__((at))
93 #else
94 #define GNUC3_ATTRIBUTE(at)
95 #endif
96
97 /* 
98  * Empty structures isn't supported by all, so to define
99  * empty structures, please protect the defn with an
100  * #if SUPPORTS_EMPTY_STRUCTS. Similarly for use,
101  * employ the macro MAYBE_EMPTY_STRUCT():
102  *
103  *     MAYBE_EMPTY_STRUCT(structFoo, fieldName);
104  */
105 #if SUPPORTS_EMPTY_STRUCTS
106 # define MAYBE_EMPTY_STRUCT(a,b) a b;
107 #else
108 # define MAYBE_EMPTY_STRUCT(a,b) /* empty */
109 #endif
110
111 /*
112  * 'Portable' 
113  */
114 #if defined(__GNUC__) || defined( __INTEL_COMPILER)
115 # define INLINE_HEADER static inline
116 # define INLINE_ME inline
117 # define STATIC_INLINE INLINE_HEADER
118 #elif defined(_MSC_VER)
119 # define INLINE_HEADER __inline static
120 # define INLINE_ME __inline
121 # define STATIC_INLINE INLINE_HEADER
122 #else
123 # error "Don't know how to inline functions with your C compiler."
124 #endif
125
126 /* TABLES_NEXT_TO_CODE says whether to assume that info tables are
127  * assumed to reside just before the code for a function.
128  *
129  * UNDEFINING THIS WON'T WORK ON ITS OWN.  You have been warned.
130  */
131 #if !defined(USE_MINIINTERPRETER) && !defined(ia64_TARGET_ARCH)
132 #define TABLES_NEXT_TO_CODE
133 #endif
134
135 /* bit macros
136  */
137 #define BITS_PER_BYTE 8
138 #define BITS_IN(x) (BITS_PER_BYTE * sizeof(x))
139
140 /* -----------------------------------------------------------------------------
141    Assertions and Debuggery
142    -------------------------------------------------------------------------- */
143
144 #ifndef DEBUG
145 #define ASSERT(predicate) /* nothing */
146 #else
147
148 void _stgAssert (char *, unsigned int);
149
150 #define ASSERT(predicate)                       \
151         if (predicate)                          \
152             /*null*/;                           \
153         else                                    \
154             _stgAssert(__FILE__, __LINE__)
155 #endif /* DEBUG */
156
157 /* 
158  * Use this on the RHS of macros which expand to nothing
159  * to make sure that the macro can be used in a context which
160  * demands a non-empty statement.
161  */
162
163 #define doNothing() do { } while (0)
164
165 /* -----------------------------------------------------------------------------
166    Global type definitions
167    -------------------------------------------------------------------------- */
168
169 #include "StgTypes.h"
170 #include "RtsTypes.h"
171
172 /* -----------------------------------------------------------------------------
173    Shorthand forms
174    -------------------------------------------------------------------------- */
175
176 typedef StgChar         C_;
177 typedef StgWord         W_;
178 typedef StgWord*        P_;
179 typedef P_*             PP_;
180 typedef StgInt          I_;
181 typedef StgAddr         A_;
182 typedef const StgWord*  D_;
183 typedef StgFunPtr       F_;
184 typedef StgByteArray    B_;
185 typedef StgClosurePtr   L_;
186
187 typedef StgInt64        LI_;
188 typedef StgWord64       LW_;
189
190 /*
191  * We often want to know the size of something in units of an
192  * StgWord... (rounded up, of course!)
193  */
194
195 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
196
197 /* 
198  * It's nice to be able to grep for casts
199  */
200
201 #define stgCast(ty,e) ((ty)(e))
202
203 /* -----------------------------------------------------------------------------
204    Include everything STG-ish
205    -------------------------------------------------------------------------- */
206
207 /* Global constaints */
208 #include "Constants.h"
209
210 /* Profiling information */
211 #include "StgProf.h"
212 #include "StgLdvProf.h"
213
214 /* Storage format definitions */
215 #include "StgFun.h"
216 #include "Closures.h"
217 #include "ClosureTypes.h"
218 #include "InfoTables.h"
219 #include "TSO.h"
220
221 /* Simulated-parallel information */
222 #include "GranSim.h"
223
224 /* Parallel information */
225 #include "Parallel.h"
226
227 /* STG/Optimised-C related stuff */
228 #include "SMP.h"
229 #include "MachRegs.h"
230 #include "Regs.h"
231 #include "Block.h"
232
233 /* RTS public interface */
234 #include "RtsAPI.h"
235
236 /* System headers: stdlib.h is eeded so that we can use NULL.  It must
237  * come after MachRegs.h, because stdlib.h might define some inline
238  * functions which may only be defined after register variables have
239  * been declared.
240  */
241 #include <stdlib.h>
242
243 #ifdef SMP
244 #include <pthread.h>
245 #endif
246
247 /* GNU mp library */
248 #include "gmp.h"
249
250 /* Storage Manager */
251 #include "StgStorage.h"
252
253 /* Macros for STG/C code */
254 #include "ClosureMacros.h"
255 #include "InfoMacros.h"
256 #include "StgMacros.h"
257 #include "PrimOps.h"
258 #include "Updates.h"
259 #include "StgTicky.h"
260 #include "CCall.h"
261 #include "Stable.h"
262
263 /* Built-in entry points */
264 #include "StgMiscClosures.h"
265
266 /* Runtime-system hooks */
267 #include "Hooks.h"
268
269 #include "Signals.h"
270
271 #include "HsFFI.h"
272
273 /* Misc stuff without a home */
274 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
275 DLL_IMPORT_RTS extern int    prog_argc;
276 DLL_IMPORT_RTS extern char  *prog_name;
277
278 extern void stackOverflow(void);
279
280 #if defined(WANT_DOTNET_SUPPORT)
281 #include "DNInvoke.h"
282 #endif
283
284 /* Creating and destroying an adjustor thunk and initialising the whole
285    adjustor thunk machinery. I cannot make myself create a separate .h file
286    for these three (sof.) 
287    
288 */
289 extern void*   createAdjustor(int cconv, StgStablePtr hptr, StgFunPtr wptr);
290 extern void    freeHaskellFunctionPtr(void* ptr);
291 extern rtsBool initAdjustor(void);
292
293 #endif /* STG_H */