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