[project @ 2003-12-28 13:09:43 by panne]
[ghc-hetmet.git] / ghc / includes / Stg.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Stg.h,v 1.60 2003/12/28 13:09:43 panne 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 /* 
92  * Empty structures isn't supported by all, so to define
93  * empty structures, please protect the defn with an
94  * #if SUPPORTS_EMPTY_STRUCTS. Similarly for use,
95  * employ the macro MAYBE_EMPTY_STRUCT():
96  *
97  *     MAYBE_EMPTY_STRUCT(structFoo, fieldName);
98  */
99 #if SUPPORTS_EMPTY_STRUCTS
100 # define MAYBE_EMPTY_STRUCT(a,b) a b;
101 #else
102 # define MAYBE_EMPTY_STRUCT(a,b) /* empty */
103 #endif
104
105 /*
106  * 'Portable' 
107  */
108 #if defined(__GNUC__)
109 # define INLINE_HEADER static inline
110 # define INLINE_ME inline
111 # define STATIC_INLINE INLINE_HEADER
112 #elif defined(_MSC_VER)
113 # define INLINE_HEADER __inline static
114 # define INLINE_ME __inline
115 # define STATIC_INLINE INLINE_HEADER
116 #else
117 # error "Don't know how to inline functions with your C compiler."
118 #endif
119
120 /* TABLES_NEXT_TO_CODE says whether to assume that info tables are
121  * assumed to reside just before the code for a function.
122  *
123  * UNDEFINING THIS WON'T WORK ON ITS OWN.  You have been warned.
124  */
125 #if !defined(USE_MINIINTERPRETER) && !defined(ia64_TARGET_ARCH)
126 #define TABLES_NEXT_TO_CODE
127 #endif
128
129 /* bit macros
130  */
131 #define BITS_PER_BYTE 8
132 #define BITS_IN(x) (BITS_PER_BYTE * sizeof(x))
133
134 /* -----------------------------------------------------------------------------
135    Assertions and Debuggery
136    -------------------------------------------------------------------------- */
137
138 #ifndef DEBUG
139 #define ASSERT(predicate) /* nothing */
140 #else
141
142 void _stgAssert (char *, unsigned int);
143
144 #define ASSERT(predicate)                       \
145         if (predicate)                          \
146             /*null*/;                           \
147         else                                    \
148             _stgAssert(__FILE__, __LINE__)
149 #endif /* DEBUG */
150
151 /* 
152  * Use this on the RHS of macros which expand to nothing
153  * to make sure that the macro can be used in a context which
154  * demands a non-empty statement.
155  */
156
157 #define doNothing() do { } while (0)
158
159 /* -----------------------------------------------------------------------------
160    Global type definitions
161    -------------------------------------------------------------------------- */
162
163 #include "StgTypes.h"
164 #include "RtsTypes.h"
165
166 /* -----------------------------------------------------------------------------
167    Shorthand forms
168    -------------------------------------------------------------------------- */
169
170 typedef StgChar         C_;
171 typedef StgWord         W_;
172 typedef StgWord*        P_;
173 typedef P_*             PP_;
174 typedef StgInt          I_;
175 typedef StgAddr         A_;
176 typedef const StgWord*  D_;
177 typedef StgFunPtr       F_;
178 typedef StgByteArray    B_;
179 typedef StgClosurePtr   L_;
180
181 typedef StgInt64        LI_;
182 typedef StgWord64       LW_;
183
184 /*
185  * We often want to know the size of something in units of an
186  * StgWord... (rounded up, of course!)
187  */
188
189 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
190
191 /* 
192  * It's nice to be able to grep for casts
193  */
194
195 #define stgCast(ty,e) ((ty)(e))
196
197 /* -----------------------------------------------------------------------------
198    Include everything STG-ish
199    -------------------------------------------------------------------------- */
200
201 /* Global constaints */
202 #include "Constants.h"
203
204 /* Profiling information */
205 #include "StgProf.h"
206 #include "StgLdvProf.h"
207
208 /* Storage format definitions */
209 #include "StgFun.h"
210 #include "Closures.h"
211 #include "ClosureTypes.h"
212 #include "InfoTables.h"
213 #include "TSO.h"
214
215 /* Simulated-parallel information */
216 #include "GranSim.h"
217
218 /* Parallel information */
219 #include "Parallel.h"
220
221 /* STG/Optimised-C related stuff */
222 #include "SMP.h"
223 #include "MachRegs.h"
224 #include "Regs.h"
225 #include "Block.h"
226
227 /* RTS public interface */
228 #include "RtsAPI.h"
229
230 /* System headers: stdlib.h is eeded so that we can use NULL.  It must
231  * come after MachRegs.h, because stdlib.h might define some inline
232  * functions which may only be defined after register variables have
233  * been declared.
234  */
235 #include <stdlib.h>
236
237 #ifdef SMP
238 #include <pthread.h>
239 #endif
240
241 /* GNU mp library */
242 #include "gmp.h"
243
244 /* Storage Manager */
245 #include "StgStorage.h"
246
247 /* Macros for STG/C code */
248 #include "ClosureMacros.h"
249 #include "InfoMacros.h"
250 #include "StgMacros.h"
251 #include "PrimOps.h"
252 #include "Updates.h"
253 #include "StgTicky.h"
254 #include "CCall.h"
255 #include "Stable.h"
256
257 /* Built-in entry points */
258 #include "StgMiscClosures.h"
259
260 /* Runtime-system hooks */
261 #include "Hooks.h"
262
263 #include "Signals.h"
264
265 #include "HsFFI.h"
266
267 /* Misc stuff without a home */
268 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
269 DLL_IMPORT_RTS extern int    prog_argc;
270 DLL_IMPORT_RTS extern char  *prog_name;
271
272 extern void stackOverflow(void);
273
274 #if defined(WANT_DOTNET_SUPPORT)
275 #include "DNInvoke.h"
276 #endif
277
278 /* Creating and destroying an adjustor thunk and initialising the whole
279    adjustor thunk machinery. I cannot make myself create a separate .h file
280    for these three (sof.) 
281    
282 */
283 extern void*   createAdjustor(int cconv, StgStablePtr hptr, StgFunPtr wptr);
284 extern void    freeHaskellFunctionPtr(void* ptr);
285 extern rtsBool initAdjustor(void);
286
287 #endif /* STG_H */