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