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