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