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