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