7e5449907955e8c13b438609ccfc71725c956096
[ghc-hetmet.git] / ghc / includes / stgdefs.h
1 /* these are the definitions included at the beginning
2  * of every compiled-to-C module
3  */
4 #ifndef STGDEFS_H
5 #define STGDEFS_H
6
7 /* machine/compiler/system dependencies :-(  Must be first! */
8 /* OLD: #include "platform.h"  generated by configure */
9 #include "config.h"   /* generated by configure */
10 #include "error.h"
11 #include "StgMachDeps.h"
12
13 #include "COptRegs.h"
14
15 /* our own ASSERT macro (for C) */
16 #ifndef DEBUG
17 #define NDEBUG 1 /* for assert.h */
18 #define ASSERT(predicate) /*nothing*/
19
20 #else
21 #undef NDEBUG   /* for assert.h */
22
23 void _stgAssert PROTO((char *, unsigned int));
24
25 #define ASSERT(predicate)                       \
26         if (predicate)                          \
27             /*null*/;                           \
28         else                                    \
29             _stgAssert(__FILE__, __LINE__)
30 #endif
31
32 #if macos7_TARGET_OS
33 #define NON_POSIX_SOURCE
34 #endif
35
36 /* If _NEXT_SOURCE is defined, certain header files make more 
37  * constants visible to us.
38  * Perhaps it would have been wise, also to define NON_POSIX_SOURCE.
39  * Things seemed to work better without it however, so I have not
40  * done it. Nevertheless we do the signal stuff in a NON_POSIX way,
41  * see StgMacros.lh.
42  * CaS
43  */
44 #ifdef nextstep3_TARGET_OS
45 #define _NEXT_SOURCE
46 #endif
47  
48 #ifdef NON_POSIX_SOURCE
49 #undef _POSIX_SOURCE
50 #undef _POSIX_C_SOURCE
51 #else
52 #define _POSIX_SOURCE 1
53 #define _POSIX_C_SOURCE 199301L
54 /* Alphas set _POSIX_VERSION (unistd.h) */
55 /* ditto _POSIX2_C_VERSION
56          _POSIX2_VERSION
57          _POSIX_4SOURCE
58 */
59
60 /* Bogus use of non-existent variable POSIX_C_SOURCE in the supplied header files
61    for gcc-2.7.1 on Solaris forces us to define it: (this strikes when using st_atime
62    and friends in <sys/stat.h> )
63 */
64
65 #if (__GNUC__ == 2) && (__GNUC_MINOR__ == 7) 
66 /* sigh, not possible to get at bugfix release number (fixed in 2.7.2) */
67 #define POSIX_C_SOURCE _POSIX_C_SOURCE
68 #endif
69
70 #include <unistd.h>
71 #include <signal.h>
72 #endif
73
74 /* these are all ANSI C headers */
75 #include <stdlib.h>
76 #include <string.h>
77 #include <math.h>
78 #include <assert.h>
79 #include <errno.h>
80 #include <stdio.h>
81
82 #ifndef STDC_HEADERS
83 /* hack: though the following are defined in the ANSI C library,
84     they may not be defined in a systems stdio.h (Suns, for example).
85     GCC is schizophrenic about whether it adds these into its
86     own headers for you; so we have no choice but to throw them in.
87 */
88 int     fclose PROTO((FILE *));
89 int     fflush PROTO((FILE *));
90 int     fgetc PROTO((FILE *));
91 int     fprintf PROTO((FILE *, const char *, ...));
92 int     fputc PROTO((int, FILE *));
93 int     fputs PROTO((const char *, FILE *));
94 size_t  fread PROTO((void *, size_t, size_t, FILE *));
95 int     fscanf PROTO((FILE *, const char *, ...));
96 int     fseek PROTO((FILE *, long int, int));
97 size_t  fwrite PROTO((const void *, size_t, size_t, FILE *));
98 void    perror PROTO((const char *));
99 int     printf PROTO((const char *, ...));
100 int     puts PROTO((const char *));
101 int     remove PROTO((const char *));
102 int     rename PROTO((const char *, const char *));
103 void    rewind PROTO((FILE *));
104 int     scanf PROTO((const char *, ...));
105 void    setbuf PROTO((FILE *, char *));
106 int     setvbuf PROTO((FILE *, char *, int, size_t));
107 int     sscanf PROTO((const char *, const char *, ...));
108 /* end of hack */
109 #endif /* STDC_HEADERS */
110
111 #if ! defined(EXIT_SUCCESS) || ! defined(EXIT_FAILURE)
112 /* "stdlib.h" should have defined these; but at least
113    on SunOS 4.1.3, this is not so.
114 */
115 #define EXIT_SUCCESS 0
116 #define EXIT_FAILURE 1
117 #endif
118
119 /* Make sure that *some* register map is defined */
120 #ifdef __STG_GCC_REGS__
121 # if !(defined(NULL_REG_MAP) || defined(FLUSH_REG_MAP) || defined(MAIN_REG_MAP) \
122     || defined(MARK_REG_MAP) || defined(SCAN_REG_MAP)  || defined(SCAV_REG_MAP))
123 yikes! no register map defined!
124 # endif
125 #endif
126
127 /* Make sure that *some* garbage-collector is expected; GCap is the default */
128 #if !(defined(GCap) || defined(GC2s) || defined(GC1s) || defined(GCdu) || defined(GCgn))
129 #define GCap 1
130 #endif
131
132 #ifdef IN_GHC_RTS
133 #define IF_RTS(x) x
134 #else
135 #define IF_RTS(x) /*nothing*/
136 #endif
137
138 /* GNU multi-precision arith */
139 #include "gmp.h"
140
141 /* typedefs for the basic entities */
142 #include "StgTypes.h"
143
144 /* constants about the system known to *everybody* (compiler & RTS) */
145 #include "GhcConstants.h"
146
147 /* macros to deal with stacks (no longer heap) growing in either dirn */
148 #include "StgDirections.h"
149
150 /* declarations for all the runtime flags for the RTS */
151 #ifdef IN_GHC_RTS
152 #include "RtsFlags.h"
153 #endif
154 /* and those that are visible *everywhere* (RTS + Haskell code) */
155 struct ALL_FLAGS {
156 #ifdef TICKY_TICKY
157     W_ doUpdEntryCounts;    /* if true, we cannot short-circuit Inds,
158                                  common-up {Int,Char}Likes or Consts
159                             */
160 #endif
161     W_ dummy_entry; /* so there is *something* in it... */
162 };
163 extern struct ALL_FLAGS AllFlags;
164
165 /* declarations for garbage collection routines */
166 #include "SMinterface.h"
167
168 /* Macros for declaring "registers" and other Optimising stuff */
169 #include "COptJumps.h"
170 #include "COptRegs.h"
171 #include "COptWraps.h"
172
173 /* these will come into play if you use -DTICKY_TICKY (default: off) */
174 #include "Ticky.h"
175
176 hash_t hash_str   PROTO((char *str));
177 hash_t hash_fixed PROTO((char *data, I_ len));
178
179 /* ullong (64bit) formatting */
180 char *ullong_format_string PROTO((ullong x, char *s, rtsBool with_commas));
181
182 /* declarations of macros for "high-level instructions" */
183 #include "StgMacros.h"
184
185 /* You always need these */
186 #include "Info.h"
187
188 /* You need these if you are using the threads package or a parallel machine... */
189 #include "Threads.h"
190 #include "Parallel.h"
191
192 /* Things will happen in here if the driver does -DPROFILING */
193 #include "CostCentre.h"
194
195 /* GRAN and PAR stuff */
196 #include "GranSim.h"
197
198 #if defined(PROFILING) || defined(CONCURRENT)
199 char * time_str(STG_NO_ARGS);
200 #endif
201
202 /* declarations for runtime-system entry points */
203 void miniInterpret PROTO((StgFunPtr));
204 void miniInterpret_debug PROTO(( StgFunPtr, void(*)(STG_NO_ARGS) ));
205 void miniInterpretEnd(STG_NO_ARGS);
206
207 StgFunPtr evaluateMain(STG_NO_ARGS);
208 StgFunPtr returnMain(STG_NO_ARGS);
209 StgFunPtr impossible_jump_after_switch(STG_NO_ARGS);
210
211 /* hooks: user might write some of their own */
212 void ErrorHdrHook       PROTO((FILE *));
213 void OutOfHeapHook      PROTO((W_, W_));
214 void StackOverflowHook  PROTO((I_));
215 #ifdef CONCURRENT
216 void NoRunnableThreadsHook (STG_NO_ARGS);
217 #endif
218 void MallocFailHook     PROTO((I_, char *));
219 void PatErrorHdrHook    PROTO((FILE *));
220 void PreTraceHook       PROTO((FILE *));
221 void PostTraceHook      PROTO((FILE *));
222 void defaultsHook       (STG_NO_ARGS);
223 void initEachPEHook     (STG_NO_ARGS);
224
225 EXTFUN(startStgWorld);
226 #ifdef CONCURRENT
227 EXTFUN(CheckHeapCode);
228 EXTFUN(Continue);
229 EXTFUN(resumeThread);
230 #endif
231
232 extern char **prog_argv; /* from runtime/main/main.lc */
233 extern int    prog_argc;
234 extern char **environ; /* we can get this one straight */
235
236 EXTDATA(STK_STUB_closure);
237
238 /* now these really *DO* need to be somewhere else... */
239 char   *time_str(STG_NO_ARGS);
240 I_      stg_exit PROTO((I_));
241 I_      _stg_rem PROTO((I_, I_));
242 char   *stgMallocBytes PROTO((I_, char *));
243 char   *stgMallocWords PROTO((I_, char *));
244
245 /* definitions for closures */
246 #include "SMClosures.h"
247
248 /* definitions for info tables */
249 #include "SMInfoTables.h"
250
251 /* declarations for Update & Indirection stuff */
252 #include "SMupdate.h"
253
254 /* declarations for runtime flags/values */
255 #define MAX_RTS_ARGS 32
256
257 /* Saving and restoring registers */
258 #include "StgRegs.h"
259
260
261 /*
262  * threadWaitWrite# uses FD_SETSIZE to distinguish
263  * between read file descriptors and write fd's.
264  * Hence we need to include <sys/types.h>, but
265  * is this the best place to do it?
266  * (the following has been moved from libposix.h)
267  */
268
269 #ifdef HAVE_SYS_TYPES_H
270 #include <sys/types.h>
271 #endif  /* HAVE_SYS_TYPES_H */
272
273 #ifndef FD_SETSIZE
274 # ifdef __FD_SETSIZE
275 #  define FD_SETSIZE __FD_SETSIZE
276 # else /* cop out */
277 #  define FD_SETSIZE 1024
278 # endif
279 #endif
280
281 #endif /* ! STGDEFS_H */