[project @ 2003-07-21 15:05:54 by simonmar]
[ghc-hetmet.git] / ghc / includes / Stg.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Stg.h,v 1.53 2003/07/21 15:05:54 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 #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    System headers
122    -------------------------------------------------------------------------- */
123
124 // Needed so that we can use NULL
125 #include <stdlib.h>
126
127 /* -----------------------------------------------------------------------------
128    Global type definitions
129    -------------------------------------------------------------------------- */
130
131 #include "StgTypes.h"
132 #include "RtsTypes.h"
133
134 /* -----------------------------------------------------------------------------
135    Shorthand forms
136    -------------------------------------------------------------------------- */
137
138 typedef StgChar         C_;
139 typedef StgWord         W_;
140 typedef StgWord*        P_;
141 typedef P_*             PP_;
142 typedef StgInt          I_;
143 typedef StgAddr         A_;
144 typedef const StgWord*  D_;
145 typedef StgFunPtr       F_;
146 typedef StgByteArray    B_;
147 typedef StgClosurePtr   L_;
148
149 typedef StgInt64        LI_;
150 typedef StgWord64       LW_;
151
152 /*
153  * We often want to know the size of something in units of an
154  * StgWord... (rounded up, of course!)
155  */
156
157 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
158
159 /* 
160  * It's nice to be able to grep for casts
161  */
162
163 #define stgCast(ty,e) ((ty)(e))
164
165 /* -----------------------------------------------------------------------------
166    Include everything STG-ish
167    -------------------------------------------------------------------------- */
168
169 /* Global constaints */
170 #include "Constants.h"
171
172 /* Profiling information */
173 #include "StgProf.h"
174 #include "StgLdvProf.h"
175
176 /* Storage format definitions */
177 #include "StgFun.h"
178 #include "Closures.h"
179 #include "ClosureTypes.h"
180 #include "InfoTables.h"
181 #include "TSO.h"
182
183 /* Simulated-parallel information */
184 #include "GranSim.h"
185
186 /* Parallel information */
187 #include "Parallel.h"
188
189 /* STG/Optimised-C related stuff */
190 #include "SMP.h"
191 #include "MachRegs.h"
192 #include "Regs.h"
193 #include "TailCalls.h"
194 #include "Block.h"
195
196 /* RTS public interface */
197 #include "RtsAPI.h"
198
199 #ifdef SMP
200 #include <pthread.h>
201 #endif
202
203 /* GNU mp library */
204 #include "gmp.h"
205
206 /* Storage Manager */
207 #include "StgStorage.h"
208
209 /* Macros for STG/C code */
210 #include "ClosureMacros.h"
211 #include "InfoMacros.h"
212 #include "StgMacros.h"
213 #include "PrimOps.h"
214 #include "Updates.h"
215 #include "StgTicky.h"
216 #include "CCall.h"
217 #include "Stable.h"
218
219 /* Built-in entry points */
220 #include "StgMiscClosures.h"
221
222 /* Runtime-system hooks */
223 #include "Hooks.h"
224
225 #include "Signals.h"
226
227 #include "HsFFI.h"
228
229 /* Misc stuff without a home */
230 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
231 DLL_IMPORT_RTS extern int    prog_argc;
232
233 extern void stackOverflow(void);
234
235 #if defined(WANT_DOTNET_SUPPORT)
236 #include "DNInvoke.h"
237 #endif
238
239 /* Creating and destroying an adjustor thunk.
240    I cannot make myself create a separate .h file
241    for these two (sof.) 
242    
243 */
244 extern void* createAdjustor(int cconv, StgStablePtr hptr, StgFunPtr wptr);
245 extern void  freeHaskellFunctionPtr(void* ptr);
246
247 #endif /* STG_H */