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