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