[project @ 2001-11-22 14:25:11 by simonmar]
[ghc-hetmet.git] / ghc / includes / Stg.h
1 /* -----------------------------------------------------------------------------
2  * $Id: Stg.h,v 1.40 2001/11/22 14:25:11 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  * ---------------------------------------------------------------------------*/
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 #include "StgRetainerProf.h"
154 #include "StgLdvProf.h"
155
156 /* Storage format definitions */
157 #include "Closures.h"
158 #include "ClosureTypes.h"
159 #include "InfoTables.h"
160 #include "TSO.h"
161
162 /* Simulated-parallel information */
163 #include "GranSim.h"
164
165 /* Parallel information */
166 #include "Parallel.h"
167
168 /* STG/Optimised-C related stuff */
169 #include "SMP.h"
170 #include "MachRegs.h"
171 #include "Regs.h"
172 #include "TailCalls.h"
173 #include "Block.h"
174
175 /* RTS public interface */
176 #include "RtsAPI.h"
177
178 /* these are all ANSI C headers */
179 #include <stdlib.h>
180 #include <string.h>
181 #include <math.h>
182 #include <assert.h>
183 #include <errno.h>
184 #include <stdio.h>
185
186 #ifdef HAVE_SIGNAL_H
187 #include <signal.h>
188 #endif
189
190 #ifdef HAVE_UNISTD_H
191 #include <unistd.h>
192 #endif
193
194 #ifdef SMP
195 #include <pthread.h>
196 #endif
197
198 /* GNU mp library */
199 #include "gmp.h"
200
201 /* Storage Manager */
202 #include "StgStorage.h"
203
204 /* Macros for STG/C code */
205 #include "ClosureMacros.h"
206 #include "InfoMacros.h"
207 #include "StgMacros.h"
208 #include "PrimOps.h"
209 #include "Updates.h"
210 #include "StgTicky.h"
211 #include "CCall.h"
212 #include "Stable.h"
213
214 /* Built-in entry points */
215 #include "StgMiscClosures.h"
216
217 /* Runtime-system hooks */
218 #include "Hooks.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 /* Creating and destroying an adjustor thunk.
229    I cannot make myself create a separate .h file
230    for these two (sof.) 
231    
232 */
233 extern void* createAdjustor(int cconv, StgStablePtr hptr, StgFunPtr wptr);
234 extern void  freeHaskellFunctionPtr(void* ptr);
235
236 #endif /* STG_H */