[project @ 1999-03-02 19:44:07 by sof]
[ghc-hetmet.git] / ghc / includes / InfoTables.h
1 /* ----------------------------------------------------------------------------
2  * $Id: InfoTables.h,v 1.12 1999/03/02 19:44:10 sof Exp $
3  * 
4  * (c) The GHC Team, 1998-1999
5  *
6  * Info Tables
7  *
8  * -------------------------------------------------------------------------- */
9
10 #ifndef INFOTABLES_H
11 #define INFOTABLES_H
12
13 /* -----------------------------------------------------------------------------
14    Profiling info
15    -------------------------------------------------------------------------- */
16
17 #ifdef PROFILING
18
19 #define PROF_INFO_WORDS n
20
21 typedef struct {
22   /* nothing yet */
23 } StgProfInfo;
24
25 #else /* !PROFILING */
26
27 #define PROF_INFO_WORDS 0
28
29 typedef struct {
30   /* empty */
31 } StgProfInfo;
32
33 #endif /* PROFILING */
34
35 /* -----------------------------------------------------------------------------
36    Parallelism info
37    -------------------------------------------------------------------------- */
38
39 #ifdef PAR
40
41 #define PAR_INFO_WORDS 0
42
43 typedef struct {
44        /* empty */
45 } StgParInfo;
46
47 #else /* !PAR */
48
49 #define PAR_INFO_WORDS 0
50
51 typedef struct {
52         /* empty */
53 } StgParInfo;
54
55 #endif /* PAR */
56
57 /* -----------------------------------------------------------------------------
58    Debugging info
59    -------------------------------------------------------------------------- */
60
61 #ifdef DEBUG_CLOSURE
62
63 #define DEBUG_INFO_WORDS n
64
65 typedef struct {
66         ... whatever ...
67 } StgDebugInfo;
68
69 #else /* !DEBUG_CLOSURE */
70
71 #define DEBUG_INFO_WORDS 0
72
73 typedef struct {
74         /* empty */
75 } StgDebugInfo;
76
77 #endif /* DEBUG_CLOSURE */
78
79 /* -----------------------------------------------------------------------------
80    Closure Types
81
82    If you add or delete any closure types, don't forget to update
83    ClosureTypes.h for the native code generator.  This is a temporary
84    measure (I hope).
85    -------------------------------------------------------------------------- */
86
87 typedef enum {
88
89     INVALID_OBJECT /* Object tag 0 raises an internal error */
90
91     , CONSTR
92     , CONSTR_1_0
93     , CONSTR_0_1
94     , CONSTR_2_0
95     , CONSTR_1_1
96     , CONSTR_0_2
97     , CONSTR_INTLIKE
98     , CONSTR_CHARLIKE
99     , CONSTR_STATIC
100     , CONSTR_NOCAF_STATIC
101
102     , FUN
103     , FUN_1_0
104     , FUN_0_1
105     , FUN_2_0
106     , FUN_1_1
107     , FUN_0_2
108     , FUN_STATIC
109
110     , THUNK
111     , THUNK_1_0
112     , THUNK_0_1
113     , THUNK_2_0
114     , THUNK_1_1
115     , THUNK_0_2
116     , THUNK_STATIC
117     , THUNK_SELECTOR
118
119     , BCO
120     , AP_UPD
121
122     , PAP  /* should be called AP_NUPD */
123
124     , IND
125     , IND_OLDGEN
126     , IND_PERM
127     , IND_OLDGEN_PERM
128     , IND_STATIC
129
130     , CAF_UNENTERED
131     , CAF_ENTERED
132     , CAF_BLACKHOLE
133
134     , RET_BCO
135     , RET_SMALL
136     , RET_VEC_SMALL
137     , RET_BIG
138     , RET_VEC_BIG
139     , RET_DYN
140     , UPDATE_FRAME
141     , CATCH_FRAME
142     , STOP_FRAME
143     , SEQ_FRAME
144
145     , BLACKHOLE
146     , BLACKHOLE_BQ
147
148     , MVAR
149
150     , ARR_WORDS
151     , MUT_ARR_PTRS
152     , MUT_ARR_PTRS_FROZEN
153
154     , MUT_VAR
155
156     , WEAK
157     , FOREIGN
158     , STABLE_NAME
159
160     , TSO
161
162     , BLOCKED_FETCH
163     , FETCH_ME
164
165     , EVACUATED
166
167     , N_CLOSURE_TYPES           /* number of distinct closure types */
168
169 } StgClosureType;
170
171 /* The type flags provide quick access to certain properties of a closure. */
172
173 #define _HNF (1<<0)  /* head normal form?  */
174 #define _BTM (1<<1)  /* bitmap-style layout? */
175 #define _NS  (1<<2)  /* non-sparkable      */
176 #define _STA (1<<3)  /* static?            */
177 #define _THU (1<<4)  /* thunk?             */
178 #define _MUT (1<<5)  /* mutable?           */
179 #define _UPT (1<<6)  /* unpointed?         */
180 #define _SRT (1<<7)  /* has an SRT?        */
181
182 #define isSTATIC(flags)    ((flags) &_STA)
183 #define isMUTABLE(flags)   ((flags) &_MUT)
184 #define isBITMAP(flags)    ((flags) &_BTM)
185 #define isTHUNK(flags)     ((flags) &_THU)
186 #define isUNPOINTED(flags) ((flags) &_UPT)
187 #define hasSRT(flags)      ((flags) &_SRT)
188
189 #define closure_STATIC(closure)       (  get_itbl(closure)->flags & _STA)
190 #define closure_SHOULD_SPARK(closure) (!(get_itbl(closure)->flags & _NS))
191 #define closure_MUTABLE(closure)      (  get_itbl(closure)->flags & _MUT)
192 #define closure_UNPOINTED(closure)    (  get_itbl(closure)->flags & _UPT)
193
194 /*                                  HNF  BTM   NS  STA  THU MUT UPT SRT */
195                                                                     
196 #define FLAGS_CONSTR               (_HNF|     _NS                        )      
197 #define FLAGS_CONSTR_1_0           (_HNF|     _NS                        )      
198 #define FLAGS_CONSTR_0_1           (_HNF|     _NS                        )      
199 #define FLAGS_CONSTR_2_0           (_HNF|     _NS                        )      
200 #define FLAGS_CONSTR_1_1           (_HNF|     _NS                        )      
201 #define FLAGS_CONSTR_0_2           (_HNF|     _NS                        )      
202 #define FLAGS_CONSTR_STATIC        (_HNF|     _NS|_STA                   )      
203 #define FLAGS_CONSTR_NOCAF_STATIC  (_HNF|     _NS|_STA                   )      
204 #define FLAGS_FUN                  (_HNF|     _NS|                  _SRT )      
205 #define FLAGS_FUN_1_0              (_HNF|     _NS                        )      
206 #define FLAGS_FUN_0_1              (_HNF|     _NS                        )      
207 #define FLAGS_FUN_2_0              (_HNF|     _NS                        )      
208 #define FLAGS_FUN_1_1              (_HNF|     _NS                        )      
209 #define FLAGS_FUN_0_2              (_HNF|     _NS                        )      
210 #define FLAGS_FUN_STATIC           (_HNF|     _NS|_STA|             _SRT )      
211 #define FLAGS_THUNK                (     _BTM|         _THU|        _SRT )      
212 #define FLAGS_THUNK_1_0            (     _BTM|         _THU|        _SRT )      
213 #define FLAGS_THUNK_0_1            (     _BTM|         _THU|        _SRT )      
214 #define FLAGS_THUNK_2_0            (     _BTM|         _THU|        _SRT )      
215 #define FLAGS_THUNK_1_1            (     _BTM|         _THU|        _SRT )      
216 #define FLAGS_THUNK_0_2            (     _BTM|         _THU|        _SRT )      
217 #define FLAGS_THUNK_STATIC         (     _BTM|    _STA|_THU|        _SRT )      
218 #define FLAGS_THUNK_SELECTOR       (     _BTM|         _THU|        _SRT )      
219 #define FLAGS_BCO                  (_HNF|     _NS                        )      
220 #define FLAGS_CAF_UNENTERED        0 /* Do we still use these? */
221 #define FLAGS_CAF_ENTERED          0
222 #define FLAGS_CAF_BLACKHOLE        (     _BTM|_NS|              _UPT     )
223 #define FLAGS_AP_UPD               (     _BTM|         _THU              )      
224 #define FLAGS_PAP                  (_HNF|     _NS                        )      
225 #define FLAGS_IND                  0
226 #define FLAGS_IND_OLDGEN           0
227 #define FLAGS_IND_PERM             0
228 #define FLAGS_IND_OLDGEN_PERM      0
229 #define FLAGS_IND_STATIC           (              _STA                   )      
230 #define FLAGS_EVACUATED            0
231 #define FLAGS_ARR_WORDS            (_HNF|     _NS|              _UPT     )      
232 #define FLAGS_MUT_ARR_PTRS         (_HNF|     _NS|         _MUT|_UPT     )      
233 #define FLAGS_MUT_ARR_PTRS_FROZEN  (_HNF|     _NS|         _MUT|_UPT     )      
234 #define FLAGS_MUT_VAR              (_HNF|     _NS|         _MUT|_UPT     )      
235 #define FLAGS_FOREIGN              (_HNF|     _NS|              _UPT     )      
236 #define FLAGS_STABLE_NAME          (_HNF|     _NS|              _UPT     )      
237 #define FLAGS_WEAK                 (_HNF|     _NS|              _UPT     )      
238 #define FLAGS_BLACKHOLE            (          _NS|              _UPT     )      
239 #define FLAGS_BLACKHOLE_BQ         (          _NS|         _MUT|_UPT     )      
240 #define FLAGS_MVAR                 (_HNF|     _NS|         _MUT|_UPT     )      
241 #define FLAGS_FETCH_ME             (_HNF|     _NS                        )      
242 #define FLAGS_TSO                  (_HNF|     _NS|         _MUT|_UPT     )
243 #define FLAGS_RET_BCO              (     _BTM                            )
244 #define FLAGS_RET_SMALL            (     _BTM|                       _SRT)
245 #define FLAGS_RET_VEC_SMALL        (     _BTM|                       _SRT)
246 #define FLAGS_RET_BIG              (                                 _SRT)
247 #define FLAGS_RET_VEC_BIG          (                                 _SRT)
248 #define FLAGS_RET_DYN              (                                 _SRT)
249 #define FLAGS_CATCH_FRAME          (     _BTM                            )
250 #define FLAGS_STOP_FRAME           (     _BTM                            )
251 #define FLAGS_SEQ_FRAME            (     _BTM                            )
252 #define FLAGS_UPDATE_FRAME         (     _BTM                            )
253
254 /* -----------------------------------------------------------------------------
255    Info Tables
256    -------------------------------------------------------------------------- */
257
258 /* A large bitmap.  Small 32-bit ones live in the info table, but sometimes
259  * 32 bits isn't enough and we have to generate a larger one.  (sizes
260  * differ for 64-bit machines.
261  */
262
263 typedef struct {
264   StgWord size;
265   StgWord bitmap[0];
266 } StgLargeBitmap;
267
268 /*
269  * Stuff describing the closure layout.  Well, actually, it might
270  * contain the selector index for a THUNK_SELECTOR.  If we're on a
271  * 64-bit architecture then we can enlarge some of these fields, since
272  * the union contains a pointer field.
273  */
274
275 typedef union {
276 #if SIZEOF_VOID_P == 8
277   struct {
278     StgWord32 ptrs;             /* number of pointers     */
279     StgWord32 nptrs;            /* number of non-pointers */
280   } payload;
281 #else
282   struct {
283     StgWord16 ptrs;             /* number of pointers     */
284     StgWord16 nptrs;            /* number of non-pointers */
285   } payload;
286
287   StgWord bitmap;               /* bit pattern, 1 = pointer, 0 = non-pointer */
288   StgWord selector_offset;      /* used in THUNK_SELECTORs */
289   StgLargeBitmap* large_bitmap; /* pointer to large bitmap structure */
290
291 #endif
292   
293 } StgClosureInfo;
294
295 /*
296  * Info tables.  All info tables are the same type, to simplify code
297  * generation.  However, the mangler removes any unused SRT fields
298  * from the asm to save space (convention: if srt_len is zero, or the
299  * type is a CONSTR_ type, then the SRT field isn't present.
300  */
301
302 typedef StgClosure* StgSRT[];
303
304 typedef struct _StgInfoTable {
305     StgSRT         *srt;        /* pointer to the SRT table */
306 #ifdef PAR
307     StgParInfo      par;
308 #endif
309 #ifdef PROFILING
310     StgProfInfo     prof;
311 #endif
312 #ifdef DEBUG_CLOSURE
313     StgDebugInfo    debug;
314 #endif
315     StgClosureInfo  layout;     /* closure layout info (pointer-sized) */
316 #if SIZEOF_VOID_P == 8
317     StgWord16       flags;      /* }                                   */
318     StgClosureType  type : 16;  /* } These 4 elements fit into 64 bits */
319     StgWord32       srt_len;    /* }                                   */
320 #else
321     StgWord8        flags;      /* }                                   */
322     StgClosureType  type : 8;   /* } These 4 elements fit into 32 bits */
323     StgWord16       srt_len;    /* }                                   */
324 #endif
325 #if USE_MINIINTERPRETER
326     StgFunPtr       (*vector)[];
327     StgFunPtr       entry;
328 #else
329     StgCode         code[0];
330 #endif
331 } StgInfoTable;
332
333 #endif /* INFOTABLES_H */