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