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