Stg.h 5.7 KB
Newer Older
1
/* -----------------------------------------------------------------------------
sof's avatar
sof committed
2
 * $Id: Stg.h,v 1.45 2002/02/13 07:48:19 sof Exp $
3
4
 *
 * (c) The GHC Team, 1998-1999
5
6
7
8
9
10
11
12
13
14
 *
 * Top-level include file for everything STG-ish.  
 *
 * This file is included *automatically* by all .hc files.
 *
 * ---------------------------------------------------------------------------*/

#ifndef STG_H
#define STG_H

15

16
17
18
19
20
/* 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.
 */
21
22
23
24
25
#ifndef IN_STG_CODE
# define IN_STG_CODE 1
#endif

#if IN_STG_CODE == 0
26
27
# ifndef NO_REGS
#  define NO_REGS			/* don't define fixed registers */
28
# endif
29
30
#endif

31
32
33
/* Configuration */
#include "config.h"

34
35
36
37
38
39
40
41
42
#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
43
44
45
46
#if defined(SMP) || defined(THREADED_RTS)
#define RTS_SUPPORTS_THREADS 1
#endif

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

rrt's avatar
rrt committed
50
51
52
53
54
/* Fix for mingw stat problem (done here so it's early enough) */
#ifdef mingw32_TARGET_OS
#define __MSVCRT__ 1
#endif

55
56
57
58
59
60
61
62
/* 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.
 */

63
64
65
66
67
68
69
70
71
72
73
/* 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
74
75
#endif

76
/* ToDo: remove */
77
78
#define COMPILER 1

79
80
81
82
83
/* 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.
 */
84
85
86
87
#ifndef USE_MINIINTERPRETER
#define TABLES_NEXT_TO_CODE
#endif

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

118
/* -----------------------------------------------------------------------------
119
   Global type definitions
120
121
   -------------------------------------------------------------------------- */

122
#include "StgTypes.h"
123
#include "RtsTypes.h"
124

125
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
/* -----------------------------------------------------------------------------
   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
   -------------------------------------------------------------------------- */

160
161
162
163
/* Global constaints */
#include "Constants.h"

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

/* Storage format definitions */
#include "Closures.h"
169
#include "ClosureTypes.h"
170
171
172
#include "InfoTables.h"
#include "TSO.h"

173
174
175
176
177
178
/* Simulated-parallel information */
#include "GranSim.h"

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

179
/* STG/Optimised-C related stuff */
180
#include "SMP.h"
181
182
183
#include "MachRegs.h"
#include "Regs.h"
#include "TailCalls.h"
184
#include "Block.h"
185

sof's avatar
sof committed
186
187
188
/* RTS public interface */
#include "RtsAPI.h"

189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/* these are all ANSI C headers */
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <assert.h>
#include <errno.h>
#include <stdio.h>

#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

205
206
207
208
#ifdef SMP
#include <pthread.h>
#endif

209
210
211
212
213
214
215
216
217
218
219
220
/* 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"
221
#include "StgTicky.h"
222
#include "CCall.h"
223
#include "Stable.h"
224
225
226
227
228
229
230

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

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

231
232
#include "HsFFI.h"

233
/* Misc stuff without a home */
sof's avatar
sof committed
234
235
DLL_IMPORT_RTS extern char **prog_argv;	/* so we can get at these from Haskell */
DLL_IMPORT_RTS extern int    prog_argc;
236

237
238
extern void stackOverflow(void);

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

247
#endif /* STG_H */