Stg.h 7.11 KB
Newer Older
1
/* -----------------------------------------------------------------------------
2
 * $Id: Stg.h,v 1.60 2003/12/28 13:09:43 panne Exp $
3
4
 *
 * (c) The GHC Team, 1998-1999
5
6
7
8
9
 *
 * Top-level include file for everything STG-ish.  
 *
 * This file is included *automatically* by all .hc files.
 *
10
11
12
13
14
 * NOTE: always include Stg.h *before* any other headers, because we
 * define some register variables which must be done before any inline
 * functions are defined (some system headers have been known to
 * define the odd inline function).
 *
15
16
17
18
19
 * ---------------------------------------------------------------------------*/

#ifndef STG_H
#define STG_H

20

21
22
23
24
25
/* If we include "Stg.h" directly, we're in STG code, and we therefore
 * get all the global register variables, macros etc. that go along
 * with that.  If "Stg.h" is included via "Rts.h", we're assumed to
 * be in vanilla C.
 */
26
27
28
29
30
#ifndef IN_STG_CODE
# define IN_STG_CODE 1
#endif

#if IN_STG_CODE == 0
31
32
# ifndef NO_REGS
#  define NO_REGS			/* don't define fixed registers */
33
# endif
34
35
#endif

36
37
38
/* Configuration */
#include "config.h"

39
40
41
42
/* This needs to be up near the top as the register line on alpha needs
 * to be before all procedures */
#include "TailCalls.h"

43
44
45
46
47
48
49
50
51
#if __GNUC__ >= 3
/* Assume that a flexible array member at the end of a struct
 * can be defined thus: T arr[]; */
#define FLEXIBLE_ARRAY
#else
/* Assume that it must be defined thus: T arr[0]; */
#define FLEXIBLE_ARRAY 0
#endif

sof's avatar
sof committed
52
53
54
55
#if defined(SMP) || defined(THREADED_RTS)
#define RTS_SUPPORTS_THREADS 1
#endif

sof's avatar
sof committed
56
57
58
/* Some macros to handle DLLing (Win32 only at the moment). */
#include "StgDLL.h"

rrt's avatar
rrt committed
59
60
61
62
63
/* Fix for mingw stat problem (done here so it's early enough) */
#ifdef mingw32_TARGET_OS
#define __MSVCRT__ 1
#endif

64
65
66
67
68
69
70
71
/* Turn lazy blackholing and eager blackholing on/off.
 *
 * Using eager blackholing makes things easier to debug because
 * the blackholes are more predictable - but it's slower and less sexy.
 *
 * For now, do lazy and not eager.
 */

72
73
74
75
76
77
78
79
80
81
82
/* TICKY_TICKY needs EAGER_BLACKHOLING to verify no double-entries of
 * single-entry thunks.
 *
 * SMP needs EAGER_BLACKHOLING because it has to lock thunks
 * synchronously, in case another thread is trying to evaluate the
 * same thunk simultaneously.
 */
#if defined(SMP) || defined(TICKY_TICKY)
#  define EAGER_BLACKHOLING
#else
#  define LAZY_BLACKHOLING
83
84
#endif

sof's avatar
sof committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#if defined(__GNUC__)
#define GNU_ATTRIBUTE(at) __attribute__((at))
#else
#define GNU_ATTRIBUTE(at)
#endif

/* 
 * Empty structures isn't supported by all, so to define
 * empty structures, please protect the defn with an
 * #if SUPPORTS_EMPTY_STRUCTS. Similarly for use,
 * employ the macro MAYBE_EMPTY_STRUCT():
 *
 *     MAYBE_EMPTY_STRUCT(structFoo, fieldName);
 */
#if SUPPORTS_EMPTY_STRUCTS
# define MAYBE_EMPTY_STRUCT(a,b) a b;
#else
# define MAYBE_EMPTY_STRUCT(a,b) /* empty */
#endif

/*
 * 'Portable' 
 */
108
#if defined(__GNUC__)
sof's avatar
sof committed
109
110
111
112
113
114
115
116
117
118
119
# define INLINE_HEADER static inline
# define INLINE_ME inline
# define STATIC_INLINE INLINE_HEADER
#elif defined(_MSC_VER)
# define INLINE_HEADER __inline static
# define INLINE_ME __inline
# define STATIC_INLINE INLINE_HEADER
#else
# error "Don't know how to inline functions with your C compiler."
#endif

120
121
122
123
124
/* TABLES_NEXT_TO_CODE says whether to assume that info tables are
 * assumed to reside just before the code for a function.
 *
 * UNDEFINING THIS WON'T WORK ON ITS OWN.  You have been warned.
 */
125
#if !defined(USE_MINIINTERPRETER) && !defined(ia64_TARGET_ARCH)
126
127
128
#define TABLES_NEXT_TO_CODE
#endif

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* bit macros
 */
#define BITS_PER_BYTE 8
#define BITS_IN(x) (BITS_PER_BYTE * sizeof(x))

/* -----------------------------------------------------------------------------
   Assertions and Debuggery
   -------------------------------------------------------------------------- */

#ifndef DEBUG
#define ASSERT(predicate) /* nothing */
#else

void _stgAssert (char *, unsigned int);

#define ASSERT(predicate)			\
	if (predicate)				\
	    /*null*/;				\
	else					\
	    _stgAssert(__FILE__, __LINE__)
#endif /* DEBUG */

sof's avatar
sof committed
151
152
153
154
155
156
157
158
/* 
 * Use this on the RHS of macros which expand to nothing
 * to make sure that the macro can be used in a context which
 * demands a non-empty statement.
 */

#define doNothing() do { } while (0)

159
/* -----------------------------------------------------------------------------
160
   Global type definitions
161
162
   -------------------------------------------------------------------------- */

163
#include "StgTypes.h"
164
#include "RtsTypes.h"
165

166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/* -----------------------------------------------------------------------------
   Shorthand forms
   -------------------------------------------------------------------------- */

typedef StgChar		C_;
typedef StgWord		W_;
typedef StgWord*	P_;
typedef P_*		PP_;
typedef StgInt		I_;
typedef StgAddr	        A_;
typedef const StgWord*  D_;
typedef StgFunPtr       F_;
typedef StgByteArray    B_;
typedef StgClosurePtr   L_;

typedef StgInt64        LI_;
typedef StgWord64       LW_;

/*
 * We often want to know the size of something in units of an
 * StgWord... (rounded up, of course!)
 */

#define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))

/* 
 * It's nice to be able to grep for casts
 */

#define stgCast(ty,e) ((ty)(e))

/* -----------------------------------------------------------------------------
   Include everything STG-ish
   -------------------------------------------------------------------------- */

201
202
203
204
/* Global constaints */
#include "Constants.h"

/* Profiling information */
205
#include "StgProf.h"
206
#include "StgLdvProf.h"
207
208

/* Storage format definitions */
209
#include "StgFun.h"
210
#include "Closures.h"
211
#include "ClosureTypes.h"
212
213
214
#include "InfoTables.h"
#include "TSO.h"

215
216
217
218
219
220
/* Simulated-parallel information */
#include "GranSim.h"

/* Parallel information */
#include "Parallel.h"

221
/* STG/Optimised-C related stuff */
222
#include "SMP.h"
223
224
#include "MachRegs.h"
#include "Regs.h"
225
#include "Block.h"
226

sof's avatar
sof committed
227
228
229
/* RTS public interface */
#include "RtsAPI.h"

230
231
232
233
234
235
236
/* System headers: stdlib.h is eeded so that we can use NULL.  It must
 * come after MachRegs.h, because stdlib.h might define some inline
 * functions which may only be defined after register variables have
 * been declared.
 */
#include <stdlib.h>

237
238
239
240
#ifdef SMP
#include <pthread.h>
#endif

241
242
243
244
245
246
247
248
249
250
251
252
/* GNU mp library */
#include "gmp.h"

/* Storage Manager */
#include "StgStorage.h"

/* Macros for STG/C code */
#include "ClosureMacros.h"
#include "InfoMacros.h"
#include "StgMacros.h"
#include "PrimOps.h"
#include "Updates.h"
253
#include "StgTicky.h"
254
#include "CCall.h"
255
#include "Stable.h"
256
257
258
259
260
261
262

/* Built-in entry points */
#include "StgMiscClosures.h"

/* Runtime-system hooks */
#include "Hooks.h"

263
264
#include "Signals.h"

265
266
#include "HsFFI.h"

267
/* Misc stuff without a home */
sof's avatar
sof committed
268
269
DLL_IMPORT_RTS extern char **prog_argv;	/* so we can get at these from Haskell */
DLL_IMPORT_RTS extern int    prog_argc;
sof's avatar
sof committed
270
DLL_IMPORT_RTS extern char  *prog_name;
271

272
273
extern void stackOverflow(void);

sof's avatar
sof committed
274
275
276
277
#if defined(WANT_DOTNET_SUPPORT)
#include "DNInvoke.h"
#endif

278
279
280
/* Creating and destroying an adjustor thunk and initialising the whole
   adjustor thunk machinery. I cannot make myself create a separate .h file
   for these three (sof.) 
sof's avatar
sof committed
281
   
sof's avatar
sof committed
282
*/
283
284
285
extern void*   createAdjustor(int cconv, StgStablePtr hptr, StgFunPtr wptr);
extern void    freeHaskellFunctionPtr(void* ptr);
extern rtsBool initAdjustor(void);
sof's avatar
sof committed
286

287
#endif /* STG_H */