1 /* -----------------------------------------------------------------------------
2 * $Id: Stg.h,v 1.62 2004/03/23 10:03:18 simonmar 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 #define GNUC3_ATTRIBUTE(at) __attribute__((at))
94 #define GNUC3_ATTRIBUTE(at)
98 * Empty structures isn't supported by all, so to define
99 * empty structures, please protect the defn with an
100 * #if SUPPORTS_EMPTY_STRUCTS. Similarly for use,
101 * employ the macro MAYBE_EMPTY_STRUCT():
103 * MAYBE_EMPTY_STRUCT(structFoo, fieldName);
105 #if SUPPORTS_EMPTY_STRUCTS
106 # define MAYBE_EMPTY_STRUCT(a,b) a b;
108 # define MAYBE_EMPTY_STRUCT(a,b) /* empty */
114 #if defined(__GNUC__) || defined( __INTEL_COMPILER)
115 # define INLINE_HEADER static inline
116 # define INLINE_ME inline
117 # define STATIC_INLINE INLINE_HEADER
118 #elif defined(_MSC_VER)
119 # define INLINE_HEADER __inline static
120 # define INLINE_ME __inline
121 # define STATIC_INLINE INLINE_HEADER
123 # error "Don't know how to inline functions with your C compiler."
126 /* TABLES_NEXT_TO_CODE says whether to assume that info tables are
127 * assumed to reside just before the code for a function.
129 * UNDEFINING THIS WON'T WORK ON ITS OWN. You have been warned.
131 #if !defined(USE_MINIINTERPRETER) && !defined(ia64_TARGET_ARCH)
132 #define TABLES_NEXT_TO_CODE
137 #define BITS_PER_BYTE 8
138 #define BITS_IN(x) (BITS_PER_BYTE * sizeof(x))
140 /* -----------------------------------------------------------------------------
141 Assertions and Debuggery
142 -------------------------------------------------------------------------- */
145 #define ASSERT(predicate) /* nothing */
148 void _stgAssert (char *, unsigned int);
150 #define ASSERT(predicate) \
154 _stgAssert(__FILE__, __LINE__)
158 * Use this on the RHS of macros which expand to nothing
159 * to make sure that the macro can be used in a context which
160 * demands a non-empty statement.
163 #define doNothing() do { } while (0)
165 /* -----------------------------------------------------------------------------
166 Global type definitions
167 -------------------------------------------------------------------------- */
169 #include "StgTypes.h"
170 #include "RtsTypes.h"
172 /* -----------------------------------------------------------------------------
174 -------------------------------------------------------------------------- */
182 typedef const StgWord* D_;
183 typedef StgFunPtr F_;
184 typedef StgByteArray B_;
185 typedef StgClosurePtr L_;
187 typedef StgInt64 LI_;
188 typedef StgWord64 LW_;
191 * We often want to know the size of something in units of an
192 * StgWord... (rounded up, of course!)
195 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
198 * It's nice to be able to grep for casts
201 #define stgCast(ty,e) ((ty)(e))
203 /* -----------------------------------------------------------------------------
204 Include everything STG-ish
205 -------------------------------------------------------------------------- */
207 /* Global constaints */
208 #include "Constants.h"
210 /* Profiling information */
212 #include "StgLdvProf.h"
214 /* Storage format definitions */
216 #include "Closures.h"
217 #include "ClosureTypes.h"
218 #include "InfoTables.h"
221 /* Simulated-parallel information */
224 /* Parallel information */
225 #include "Parallel.h"
227 /* STG/Optimised-C related stuff */
229 #include "MachRegs.h"
233 /* RTS public interface */
236 /* System headers: stdlib.h is eeded so that we can use NULL. It must
237 * come after MachRegs.h, because stdlib.h might define some inline
238 * functions which may only be defined after register variables have
250 /* Storage Manager */
251 #include "StgStorage.h"
253 /* Macros for STG/C code */
254 #include "ClosureMacros.h"
255 #include "InfoMacros.h"
256 #include "StgMacros.h"
259 #include "StgTicky.h"
263 /* Built-in entry points */
264 #include "StgMiscClosures.h"
266 /* Runtime-system hooks */
273 /* Misc stuff without a home */
274 DLL_IMPORT_RTS extern char **prog_argv; /* so we can get at these from Haskell */
275 DLL_IMPORT_RTS extern int prog_argc;
276 DLL_IMPORT_RTS extern char *prog_name;
278 extern void stackOverflow(void);
280 #if defined(WANT_DOTNET_SUPPORT)
281 #include "DNInvoke.h"
284 /* Creating and destroying an adjustor thunk and initialising the whole
285 adjustor thunk machinery. I cannot make myself create a separate .h file
286 for these three (sof.)
289 extern void* createAdjustor(int cconv, StgStablePtr hptr, StgFunPtr wptr);
290 extern void freeHaskellFunctionPtr(void* ptr);
291 extern rtsBool initAdjustor(void);