[project @ 2003-05-29 14:39:26 by sof]
[ghc-hetmet.git] / ghc / includes / Stg.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Stg.h,v 1.52 2003/05/29 14:39:30 sof 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 #if __GNUC__ >= 3
40 /* Assume that a flexible array member at the end of a struct
41  * can be defined thus: T arr[]; */
42 #define FLEXIBLE_ARRAY
43 #else
44 /* Assume that it must be defined thus: T arr[0]; */
45 #define FLEXIBLE_ARRAY 0
46 #endif
47
48 #if defined(SMP) || defined(THREADED_RTS)
49 #define RTS_SUPPORTS_THREADS 1
50 #endif
51
52 /* Some macros to handle DLLing (Win32 only at the moment). */
53 #include "StgDLL.h"
54
55 /* Fix for mingw stat problem (done here so it's early enough) */
56 #ifdef mingw32_TARGET_OS
57 #define __MSVCRT__ 1
58 #endif
59
60 /* Turn lazy blackholing and eager blackholing on/off.
61  *
62  * Using eager blackholing makes things easier to debug because
63  * the blackholes are more predictable - but it's slower and less sexy.
64  *
65  * For now, do lazy and not eager.
66  */
67
68 /* TICKY_TICKY needs EAGER_BLACKHOLING to verify no double-entries of
69  * single-entry thunks.
70  *
71  * SMP needs EAGER_BLACKHOLING because it has to lock thunks
72  * synchronously, in case another thread is trying to evaluate the
73  * same thunk simultaneously.
74  */
75 #if defined(SMP) || defined(TICKY_TICKY)
76 #  define EAGER_BLACKHOLING
77 #else
78 #  define LAZY_BLACKHOLING
79 #endif
80
81 /* TABLES_NEXT_TO_CODE says whether to assume that info tables are
82  * assumed to reside just before the code for a function.
83  *
84  * UNDEFINING THIS WON'T WORK ON ITS OWN.  You have been warned.
85  */
86 #if !defined(USE_MINIINTERPRETER) && !defined(ia64_TARGET_ARCH)
87 #define TABLES_NEXT_TO_CODE
88 #endif
89
90 /* bit macros
91  */
92 #define BITS_PER_BYTE 8
93 #define BITS_IN(x) (BITS_PER_BYTE * sizeof(x))
94
95 /* -----------------------------------------------------------------------------
96    Assertions and Debuggery
97    -------------------------------------------------------------------------- */
98
99 #ifndef DEBUG
100 #define ASSERT(predicate) /* nothing */
101 #else
102
103 void _stgAssert (char *, unsigned int);
104
105 #define ASSERT(predicate)                       \
106         if (predicate)                          \
107             /*null*/;                           \
108         else                                    \
109             _stgAssert(__FILE__, __LINE__)
110 #endif /* DEBUG */
111
112 /* 
113  * Use this on the RHS of macros which expand to nothing
114  * to make sure that the macro can be used in a context which
115  * demands a non-empty statement.
116  */
117
118 #define doNothing() do { } while (0)
119
120 /* -----------------------------------------------------------------------------
121    Global type definitions
122    -------------------------------------------------------------------------- */
123
124 #include "StgTypes.h"
125 #include "RtsTypes.h"
126
127 /* -----------------------------------------------------------------------------
128    Shorthand forms
129    -------------------------------------------------------------------------- */
130
131 typedef StgChar         C_;
132 typedef StgWord         W_;
133 typedef StgWord*        P_;
134 typedef P_*             PP_;
135 typedef StgInt          I_;
136 typedef StgAddr         A_;
137 typedef const StgWord*  D_;
138 typedef StgFunPtr       F_;
139 typedef StgByteArray    B_;
140 typedef StgClosurePtr   L_;
141
142 typedef StgInt64        LI_;
143 typedef StgWord64       LW_;
144
145 /*
146  * We often want to know the size of something in units of an
147  * StgWord... (rounded up, of course!)
148  */
149
150 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
151
152 /* 
153  * It's nice to be able to grep for casts
154  */
155
156 #define stgCast(ty,e) ((ty)(e))
157
158 /* -----------------------------------------------------------------------------
159    Include everything STG-ish
160    -------------------------------------------------------------------------- */
161
162 /* Global constaints */
163 #include "Constants.h"
164
165 /* Profiling information */
166 #include "StgProf.h"
167 #include "StgLdvProf.h"
168
169 /* Storage format definitions */
170 #include "StgFun.h"
171 #include "Closures.h"
172 #include "ClosureTypes.h"
173 #include "InfoTables.h"
174 #include "TSO.h"
175
176 /* Simulated-parallel information */
177 #include "GranSim.h"
178
179 /* Parallel information */
180 #include "Parallel.h"
181
182 /* STG/Optimised-C related stuff */
183 #include "SMP.h"
184 #include "MachRegs.h"
185 #include "Regs.h"
186 #include "TailCalls.h"
187 #include "Block.h"
188
189 /* RTS public interface */
190 #include "RtsAPI.h"
191
192 #ifdef SMP
193 #include <pthread.h>
194 #endif
195
196 /* GNU mp library */
197 #include "gmp.h"
198
199 /* Storage Manager */
200 #include "StgStorage.h"
201
202 /* Macros for STG/C code */
203 #include "ClosureMacros.h"
204 #include "InfoMacros.h"
205 #include "StgMacros.h"
206 #include "PrimOps.h"
207 #include "Updates.h"
208 #include "StgTicky.h"
209 #include "CCall.h"
210 #include "Stable.h"
211
212 /* Built-in entry points */
213 #include "StgMiscClosures.h"
214
215 /* Runtime-system hooks */
216 #include "Hooks.h"
217
218 #include "Signals.h"
219
220 #include "HsFFI.h"
221
222 /* Misc stuff without a home */
223 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
224 DLL_IMPORT_RTS extern int    prog_argc;
225
226 extern void stackOverflow(void);
227
228 #if defined(WANT_DOTNET_SUPPORT)
229 #include "DNInvoke.h"
230 #endif
231
232 /* Creating and destroying an adjustor thunk.
233    I cannot make myself create a separate .h file
234    for these two (sof.) 
235    
236 */
237 extern void* createAdjustor(int cconv, StgStablePtr hptr, StgFunPtr wptr);
238 extern void  freeHaskellFunctionPtr(void* ptr);
239
240 #endif /* STG_H */