[project @ 2001-10-27 21:44:54 by sof]
[ghc-hetmet.git] / ghc / includes / Stg.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Stg.h,v 1.39 2001/10/27 21:44:54 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  * ---------------------------------------------------------------------------*/
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    Global type definitions
108    -------------------------------------------------------------------------- */
109
110 #include "StgTypes.h"
111 #include "RtsTypes.h"
112
113 /* -----------------------------------------------------------------------------
114    Shorthand forms
115    -------------------------------------------------------------------------- */
116
117 typedef StgChar         C_;
118 typedef StgWord         W_;
119 typedef StgWord*        P_;
120 typedef P_*             PP_;
121 typedef StgInt          I_;
122 typedef StgAddr         A_;
123 typedef const StgWord*  D_;
124 typedef StgFunPtr       F_;
125 typedef StgByteArray    B_;
126 typedef StgClosurePtr   L_;
127
128 typedef StgInt64        LI_;
129 typedef StgWord64       LW_;
130
131 /*
132  * We often want to know the size of something in units of an
133  * StgWord... (rounded up, of course!)
134  */
135
136 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
137
138 /* 
139  * It's nice to be able to grep for casts
140  */
141
142 #define stgCast(ty,e) ((ty)(e))
143
144 /* -----------------------------------------------------------------------------
145    Include everything STG-ish
146    -------------------------------------------------------------------------- */
147
148 /* Global constaints */
149 #include "Constants.h"
150
151 /* Profiling information */
152 #include "StgProf.h"
153
154 /* Storage format definitions */
155 #include "Closures.h"
156 #include "ClosureTypes.h"
157 #include "InfoTables.h"
158 #include "TSO.h"
159
160 /* Simulated-parallel information */
161 #include "GranSim.h"
162
163 /* Parallel information */
164 #include "Parallel.h"
165
166 /* STG/Optimised-C related stuff */
167 #include "SMP.h"
168 #include "MachRegs.h"
169 #include "Regs.h"
170 #include "TailCalls.h"
171 #include "Block.h"
172
173 /* RTS public interface */
174 #include "RtsAPI.h"
175
176 /* these are all ANSI C headers */
177 #include <stdlib.h>
178 #include <string.h>
179 #include <math.h>
180 #include <assert.h>
181 #include <errno.h>
182 #include <stdio.h>
183
184 #ifdef HAVE_SIGNAL_H
185 #include <signal.h>
186 #endif
187
188 #ifdef HAVE_UNISTD_H
189 #include <unistd.h>
190 #endif
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 "HsFFI.h"
219
220 /* Misc stuff without a home */
221 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
222 DLL_IMPORT_RTS extern int    prog_argc;
223
224 extern void stackOverflow(void);
225
226 /* Creating and destroying an adjustor thunk.
227    I cannot make myself create a separate .h file
228    for these two (sof.) 
229    
230 */
231 extern void* createAdjustor(int cconv, StgStablePtr hptr, StgFunPtr wptr);
232 extern void  freeHaskellFunctionPtr(void* ptr);
233
234 #endif /* STG_H */