1 /* -----------------------------------------------------------------------------
2 * $Id: Stg.h,v 1.59 2003/11/14 14:28:08 stolz Exp $
4 * (c) The GHC Team, 1998-1999
6 * Top-level include file for everything STG-ish.
8 * This file is included *automatically* by all .hc files.
10 * NOTE: always include Stg.h *before* any other headers, because we
11 * define some register variables which must be done before any inline
12 * functions are defined (some system headers have been known to
13 * define the odd inline function).
15 * ---------------------------------------------------------------------------*/
21 /* If we include "Stg.h" directly, we're in STG code, and we therefore
22 * get all the global register variables, macros etc. that go along
23 * with that. If "Stg.h" is included via "Rts.h", we're assumed to
27 # define IN_STG_CODE 1
32 # define NO_REGS /* don't define fixed registers */
39 /* This needs to be up near the top as the register line on alpha needs
40 * to be before all procedures */
41 #include "TailCalls.h"
44 /* Assume that a flexible array member at the end of a struct
45 * can be defined thus: T arr[]; */
46 #define FLEXIBLE_ARRAY
48 /* Assume that it must be defined thus: T arr[0]; */
49 #define FLEXIBLE_ARRAY 0
52 #if defined(SMP) || defined(THREADED_RTS)
53 #define RTS_SUPPORTS_THREADS 1
56 /* Some macros to handle DLLing (Win32 only at the moment). */
59 /* Fix for mingw stat problem (done here so it's early enough) */
60 #ifdef mingw32_TARGET_OS
64 /* Turn lazy blackholing and eager blackholing on/off.
66 * Using eager blackholing makes things easier to debug because
67 * the blackholes are more predictable - but it's slower and less sexy.
69 * For now, do lazy and not eager.
72 /* TICKY_TICKY needs EAGER_BLACKHOLING to verify no double-entries of
73 * single-entry thunks.
75 * SMP needs EAGER_BLACKHOLING because it has to lock thunks
76 * synchronously, in case another thread is trying to evaluate the
77 * same thunk simultaneously.
79 #if defined(SMP) || defined(TICKY_TICKY)
80 # define EAGER_BLACKHOLING
82 # define LAZY_BLACKHOLING
86 #define GNU_ATTRIBUTE(at) __attribute__((at))
88 #define GNU_ATTRIBUTE(at)
92 * Empty structures isn't supported by all, so to define
93 * empty structures, please protect the defn with an
94 * #if SUPPORTS_EMPTY_STRUCTS. Similarly for use,
95 * employ the macro MAYBE_EMPTY_STRUCT():
97 * MAYBE_EMPTY_STRUCT(structFoo, fieldName);
99 #if SUPPORTS_EMPTY_STRUCTS
100 # define MAYBE_EMPTY_STRUCT(a,b) a b;
102 # define MAYBE_EMPTY_STRUCT(a,b) /* empty */
108 #if defined(__GNUC__)
109 # define INLINE_HEADER static inline
110 # define INLINE_ME inline
111 # define STATIC_INLINE INLINE_HEADER
112 #elif defined(_MSC_VER)
113 # define INLINE_HEADER __inline static
114 # define INLINE_ME __inline
115 # define STATIC_INLINE INLINE_HEADER
117 # error "Don't know how to inline functions with your C compiler."
120 /* TABLES_NEXT_TO_CODE says whether to assume that info tables are
121 * assumed to reside just before the code for a function.
123 * UNDEFINING THIS WON'T WORK ON ITS OWN. You have been warned.
125 #if !defined(USE_MINIINTERPRETER) && !defined(ia64_TARGET_ARCH)
126 #define TABLES_NEXT_TO_CODE
131 #define BITS_PER_BYTE 8
132 #define BITS_IN(x) (BITS_PER_BYTE * sizeof(x))
134 /* -----------------------------------------------------------------------------
135 Assertions and Debuggery
136 -------------------------------------------------------------------------- */
139 #define ASSERT(predicate) /* nothing */
142 void _stgAssert (char *, unsigned int);
144 #define ASSERT(predicate) \
148 _stgAssert(__FILE__, __LINE__)
152 * Use this on the RHS of macros which expand to nothing
153 * to make sure that the macro can be used in a context which
154 * demands a non-empty statement.
157 #define doNothing() do { } while (0)
159 /* -----------------------------------------------------------------------------
160 Global type definitions
161 -------------------------------------------------------------------------- */
163 #include "StgTypes.h"
164 #include "RtsTypes.h"
166 /* -----------------------------------------------------------------------------
168 -------------------------------------------------------------------------- */
176 typedef const StgWord* D_;
177 typedef StgFunPtr F_;
178 typedef StgByteArray B_;
179 typedef StgClosurePtr L_;
181 typedef StgInt64 LI_;
182 typedef StgWord64 LW_;
185 * We often want to know the size of something in units of an
186 * StgWord... (rounded up, of course!)
189 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
192 * It's nice to be able to grep for casts
195 #define stgCast(ty,e) ((ty)(e))
197 /* -----------------------------------------------------------------------------
198 Include everything STG-ish
199 -------------------------------------------------------------------------- */
201 /* Global constaints */
202 #include "Constants.h"
204 /* Profiling information */
206 #include "StgLdvProf.h"
208 /* Storage format definitions */
210 #include "Closures.h"
211 #include "ClosureTypes.h"
212 #include "InfoTables.h"
215 /* Simulated-parallel information */
218 /* Parallel information */
219 #include "Parallel.h"
221 /* STG/Optimised-C related stuff */
223 #include "MachRegs.h"
227 /* RTS public interface */
230 /* System headers: stdlib.h is eeded so that we can use NULL. It must
231 * come after MachRegs.h, because stdlib.h might define some inline
232 * functions which may only be defined after register variables have
244 /* Storage Manager */
245 #include "StgStorage.h"
247 /* Macros for STG/C code */
248 #include "ClosureMacros.h"
249 #include "InfoMacros.h"
250 #include "StgMacros.h"
253 #include "StgTicky.h"
257 /* Built-in entry points */
258 #include "StgMiscClosures.h"
260 /* Runtime-system hooks */
267 /* Misc stuff without a home */
268 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
269 DLL_IMPORT_RTS extern int prog_argc;
270 DLL_IMPORT_RTS extern char *prog_name;
272 extern void stackOverflow(void);
274 #if defined(WANT_DOTNET_SUPPORT)
275 #include "DNInvoke.h"
278 /* Creating and destroying an adjustor thunk.
279 I cannot make myself create a separate .h file
283 extern void* createAdjustor(int cconv, StgStablePtr hptr, StgFunPtr wptr);
284 extern void freeHaskellFunctionPtr(void* ptr);