Stg.h 6.08 KB
Newer Older
1
/* -----------------------------------------------------------------------------
sof's avatar
sof committed
2
 * $Id: Stg.h,v 1.55 2003/08/22 22:24:16 sof 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
43
44
45
46
47
#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
48
49
50
51
#if defined(SMP) || defined(THREADED_RTS)
#define RTS_SUPPORTS_THREADS 1
#endif

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

rrt's avatar
rrt committed
55
56
57
58
59
/* Fix for mingw stat problem (done here so it's early enough) */
#ifdef mingw32_TARGET_OS
#define __MSVCRT__ 1
#endif

60
61
62
63
64
65
66
67
/* 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.
 */

68
69
70
71
72
73
74
75
76
77
78
/* 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
79
80
#endif

81
82
83
84
85
/* 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.
 */
86
#if !defined(USE_MINIINTERPRETER) && !defined(ia64_TARGET_ARCH)
87
88
89
#define TABLES_NEXT_TO_CODE
#endif

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* 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
112
113
114
115
116
117
118
119
/* 
 * 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)

120
/* -----------------------------------------------------------------------------
121
   Global type definitions
122
123
   -------------------------------------------------------------------------- */

124
#include "StgTypes.h"
125
#include "RtsTypes.h"
126

127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/* -----------------------------------------------------------------------------
   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
   -------------------------------------------------------------------------- */

162
163
164
165
/* Global constaints */
#include "Constants.h"

/* Profiling information */
166
#include "StgProf.h"
167
#include "StgLdvProf.h"
168
169

/* Storage format definitions */
170
#include "StgFun.h"
171
#include "Closures.h"
172
#include "ClosureTypes.h"
173
174
175
#include "InfoTables.h"
#include "TSO.h"

176
177
178
179
180
181
/* Simulated-parallel information */
#include "GranSim.h"

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

182
/* STG/Optimised-C related stuff */
183
#include "SMP.h"
184
185
186
#include "MachRegs.h"
#include "Regs.h"
#include "TailCalls.h"
187
#include "Block.h"
188

sof's avatar
sof committed
189
190
191
/* RTS public interface */
#include "RtsAPI.h"

192
193
194
195
196
197
198
/* 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>

199
200
201
202
#ifdef SMP
#include <pthread.h>
#endif

203
204
205
206
207
208
209
210
211
212
213
214
/* 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"
215
#include "StgTicky.h"
216
#include "CCall.h"
217
#include "Stable.h"
218
219
220
221
222
223
224

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

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

225
226
#include "Signals.h"

227
228
#include "HsFFI.h"

229
/* Misc stuff without a home */
sof's avatar
sof committed
230
231
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
232
DLL_IMPORT_RTS extern char  *prog_name;
233

234
235
extern void stackOverflow(void);

sof's avatar
sof committed
236
237
238
239
#if defined(WANT_DOTNET_SUPPORT)
#include "DNInvoke.h"
#endif

sof's avatar
sof committed
240
/* Creating and destroying an adjustor thunk.
241
   I cannot make myself create a separate .h file
sof's avatar
sof committed
242
243
   for these two (sof.) 
   
sof's avatar
sof committed
244
245
246
247
*/
extern void* createAdjustor(int cconv, StgStablePtr hptr, StgFunPtr wptr);
extern void  freeHaskellFunctionPtr(void* ptr);

248
#endif /* STG_H */