Stg.h 7.25 KB
Newer Older
1
/* -----------------------------------------------------------------------------
2
 * $Id: Stg.h,v 1.62 2004/03/23 10:03:18 simonmar 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
#if defined(__GNUC__)
#define GNU_ATTRIBUTE(at) __attribute__((at))
#else
#define GNU_ATTRIBUTE(at)
#endif

91
92
93
94
95
96
#if __GNUC__ >= 3 
#define GNUC3_ATTRIBUTE(at) __attribute__((at))
#else
#define GNUC3_ATTRIBUTE(at)
#endif

sof's avatar
sof committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* 
 * 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' 
 */
114
#if defined(__GNUC__) || defined( __INTEL_COMPILER)
sof's avatar
sof committed
115
116
117
118
119
120
121
122
123
124
125
# 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

126
127
128
129
130
/* 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.
 */
131
#if !defined(USE_MINIINTERPRETER) && !defined(ia64_TARGET_ARCH)
132
133
134
#define TABLES_NEXT_TO_CODE
#endif

135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/* 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
157
158
159
160
161
162
163
164
/* 
 * 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)

165
/* -----------------------------------------------------------------------------
166
   Global type definitions
167
168
   -------------------------------------------------------------------------- */

169
#include "StgTypes.h"
170
#include "RtsTypes.h"
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
201
202
203
204
205
206
/* -----------------------------------------------------------------------------
   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
   -------------------------------------------------------------------------- */

207
208
209
210
/* Global constaints */
#include "Constants.h"

/* Profiling information */
211
#include "StgProf.h"
212
#include "StgLdvProf.h"
213
214

/* Storage format definitions */
215
#include "StgFun.h"
216
#include "Closures.h"
217
#include "ClosureTypes.h"
218
219
220
#include "InfoTables.h"
#include "TSO.h"

221
222
223
224
225
226
/* Simulated-parallel information */
#include "GranSim.h"

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

227
/* STG/Optimised-C related stuff */
228
#include "SMP.h"
229
230
#include "MachRegs.h"
#include "Regs.h"
231
#include "Block.h"
232

sof's avatar
sof committed
233
234
235
/* RTS public interface */
#include "RtsAPI.h"

236
237
238
239
240
241
242
/* 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>

243
244
245
246
#ifdef SMP
#include <pthread.h>
#endif

247
248
249
250
251
252
253
254
255
256
257
258
/* 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"
259
#include "StgTicky.h"
260
#include "CCall.h"
261
#include "Stable.h"
262
263
264
265
266
267
268

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

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

269
270
#include "Signals.h"

271
272
#include "HsFFI.h"

273
/* Misc stuff without a home */
sof's avatar
sof committed
274
275
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
276
DLL_IMPORT_RTS extern char  *prog_name;
277

278
279
extern void stackOverflow(void);

sof's avatar
sof committed
280
281
282
283
#if defined(WANT_DOTNET_SUPPORT)
#include "DNInvoke.h"
#endif

284
285
286
/* 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
287
   
sof's avatar
sof committed
288
*/
289
290
291
extern void*   createAdjustor(int cconv, StgStablePtr hptr, StgFunPtr wptr);
extern void    freeHaskellFunctionPtr(void* ptr);
extern rtsBool initAdjustor(void);
sof's avatar
sof committed
292

293
#endif /* STG_H */