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