e04ebee44803a38b1e636f2fd60d81a0d8b5f854
[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 #include <unistd.h>
43 #include <signal.h>
44 #endif
45
46 /* these are all ANSI C headers */
47 #include <stdlib.h>
48 #include <string.h>
49 #include <math.h>
50 #include <assert.h>
51 #include <errno.h>
52 #include <stdio.h>
53
54 #ifndef STDC_HEADERS
55 /* hack: though the following are defined in the ANSI C library,
56     they may not be defined in a systems stdio.h (Suns, for example).
57     GCC is schizophrenic about whether it adds these into its
58     own headers for you; so we have no choice but to throw them in.
59 */
60 extern int fclose PROTO((FILE *));
61 extern int fflush PROTO((FILE *));
62 extern int fgetc PROTO((FILE *));
63 /* extern int fgetpos PROTO((FILE *, fpos_t *)); */
64 extern int fprintf PROTO((FILE *, const char *, ...));
65 extern int fputc PROTO((int, FILE *));
66 extern int fputs PROTO((const char *, FILE *));
67 extern size_t fread PROTO((void *, size_t, size_t, FILE *));
68 extern int fscanf PROTO((FILE *, const char *, ...));
69 extern int fseek PROTO((FILE *, long int, int));
70 /* extern int fsetpos PROTO((FILE *, const fpos_t *)); */
71 extern size_t fwrite PROTO((const void *, size_t, size_t, FILE *));
72 extern void perror PROTO((const char *));
73 extern int printf PROTO((const char *, ...));
74 extern int puts PROTO((const char *));
75 extern int remove PROTO((const char *));
76 extern int rename PROTO((const char *, const char *));
77 extern void rewind PROTO((FILE *));
78 extern int scanf PROTO((const char *, ...));
79 extern void setbuf PROTO((FILE *, char *));
80 extern int setvbuf PROTO((FILE *, char *, int, size_t));
81 extern int sscanf PROTO((const char *, const char *, ...));
82 /* end of hack */
83 #endif /* STDC_HEADERS */
84
85 #if ! defined(EXIT_SUCCESS) || ! defined(EXIT_FAILURE)
86 /* "stdlib.h" should have defined these; but at least
87    on SunOS 4.1.3, this is not so.
88 */
89 #define EXIT_SUCCESS 0
90 #define EXIT_FAILURE 1
91 #endif
92
93 /* Make sure that *some* register map is defined */
94 #ifdef __STG_GCC_REGS__
95 # if !(defined(NULL_REG_MAP) || defined(FLUSH_REG_MAP) || defined(MAIN_REG_MAP) \
96     || defined(MARK_REG_MAP) || defined(SCAN_REG_MAP)  || defined(SCAV_REG_MAP))
97 yikes! no register map defined!
98 # endif
99 #endif
100
101 /* Make sure that *some* garbage-collector is expected; GCap is the default */
102 #if !(defined(GCap) || defined(GC2s) || defined(GC1s) || defined(GCdu) || defined(GCgn))
103 #define GCap 1
104 #endif
105
106 #ifdef IN_GHC_RTS
107 #define IF_RTS(x) x
108 #else
109 #define IF_RTS(x) /*nothing*/
110 #endif
111
112 /* GNU multi-precision arith */
113 #include "gmp.h"
114
115 /* typedefs for the basic entities */
116 #include "StgTypes.h"
117
118 /* constants about the system known to *everybody* (compiler & RTS) */
119 #include "GhcConstants.h"
120
121 /* macros to deal with stacks (no longer heap) growing in either dirn */
122 #include "StgDirections.h"
123
124 /* declarations for garbage collection routines */
125 #include "SMinterface.h"
126
127 /* Macros for declaring "registers" and other Optimising stuff */
128 #include "COptJumps.h"
129 #include "COptRegs.h"
130 #include "COptWraps.h"
131
132 /* these will come into play if you use -DDO_RUNTIME_PROFILING (default: off) */
133 #include "RednCounts.h"
134
135 extern hash_t hash_str   PROTO((char *str));
136 extern hash_t hash_fixed PROTO((char *data, I_ len));
137 extern I_     decode     PROTO((char *s));
138
139 /* ullong (64bit) formatting */
140 char *ullong_format_string PROTO((ullong x, char *s, rtsBool with_commas));
141
142 /* declarations of macros for "high-level instructions" */
143 #include "StgMacros.h"
144
145 /* You always need these */
146 #include "Info.h"
147
148 /* You need these if you are using the threads package or a parallel machine... */
149 #include "Threads.h"
150 #include "Parallel.h"
151
152 /* Things will happen in here if the driver does -DUSE_COST_CENTRES */
153 #include "CostCentre.h"
154
155 /* These will come into play if you use -DLIFE_PROFILE or -DHEAP_PROF_WITH_AGE */
156 #include "AgeProfile.h"
157
158 /* These will come into play if you use -DFORCE_GC  */
159 #include "Force_GC.h"
160
161 /* GRAN and PAR stuff */
162 #include "GranSim.h"
163
164 #if defined(USE_COST_CENTRES) || defined(CONCURRENT)
165 char * time_str(STG_NO_ARGS);
166 #endif
167
168 /* declarations for runtime-system entry points */
169 extern void miniInterpret PROTO((StgFunPtr));
170 extern void miniInterpret_debug PROTO(( StgFunPtr, void(*)(STG_NO_ARGS) ));
171 extern void miniInterpretEnd(STG_NO_ARGS);
172
173 extern StgFunPtr evaluateMain(STG_NO_ARGS);
174 extern StgFunPtr returnMain(STG_NO_ARGS);
175 extern StgFunPtr impossible_jump_after_switch(STG_NO_ARGS);
176
177 /* hooks: user might write some of their own */
178 extern void ErrorHdrHook        PROTO((FILE *));
179 extern void OutOfHeapHook       PROTO((W_, W_));
180 extern void StackOverflowHook   PROTO((I_));
181 extern void MallocFailHook      PROTO((I_));
182 extern void PatErrorHdrHook     PROTO((FILE *));
183 extern void PreTraceHook        PROTO((FILE *));
184 extern void PostTraceHook       PROTO((FILE *));
185
186 EXTFUN(startStgWorld);
187 #ifdef CONCURRENT
188 EXTFUN(CheckHeapCode);
189 EXTFUN(Continue);
190 EXTFUN(resumeThread);
191 #endif
192
193 extern char **prog_argv; /* from runtime/main/main.lc */
194 extern I_     prog_argc;
195 extern char **environ; /* we can get this one straight */
196
197 EXTDATA(STK_STUB_closure);
198
199 /* now these really *DO* need to be somewhere else... */
200 extern char     *time_str(STG_NO_ARGS);
201 extern I_       stg_exit PROTO((I_));
202 extern I_       _stg_rem PROTO((I_, I_));
203
204 /* definitions for closures */
205 #include "SMClosures.h"
206
207 /* definitions for info tables */
208 #include "SMInfoTables.h"
209
210 /* declarations for Update & Indirection stuff */
211 #include "SMupdate.h"
212
213 /* declarations for runtime flags/values */
214 #define MAX_RTS_ARGS 32
215
216 /* Saving and restoring registers */
217 #include "StgRegs.h"
218
219 #endif /* ! STGDEFS_H */