[project @ 1999-01-26 11:12:41 by simonm]
[ghc-hetmet.git] / ghc / includes / InfoTables.h
1 /* ----------------------------------------------------------------------------
2  * $Id: InfoTables.h,v 1.6 1999/01/26 11:12:55 simonm 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     , CONSTR
89     /* CONSTR_p_np */
90     , CONSTR_INTLIKE
91     , CONSTR_CHARLIKE
92     , CONSTR_STATIC
93     , CONSTR_NOCAF_STATIC
94
95     , FUN
96     , FUN_STATIC
97
98     , THUNK
99     /* THUNK_p_np */
100     , THUNK_STATIC
101     , THUNK_SELECTOR
102
103     , BCO
104     , AP_UPD
105
106     , PAP  /* should be called AP_NUPD */
107
108     , IND
109     , IND_OLDGEN
110     , IND_PERM
111     , IND_OLDGEN_PERM
112     , IND_STATIC
113
114     , CAF_UNENTERED
115     , CAF_ENTERED
116     , CAF_BLACKHOLE
117
118     , RET_BCO
119     , RET_SMALL
120     , RET_VEC_SMALL
121     , RET_BIG
122     , RET_VEC_BIG
123     , RET_DYN
124     , UPDATE_FRAME
125     , CATCH_FRAME
126     , STOP_FRAME
127     , SEQ_FRAME
128
129     , BLACKHOLE
130     , BLACKHOLE_BQ
131
132     , MVAR
133
134     , ARR_WORDS
135     , MUT_ARR_WORDS
136
137     , MUT_ARR_PTRS
138     , MUT_ARR_PTRS_FROZEN
139
140     , MUT_VAR
141
142     , WEAK
143     , FOREIGN
144     , STABLE_NAME
145
146     , TSO
147
148     , BLOCKED_FETCH
149     , FETCH_ME
150
151     , EVACUATED
152
153     , N_CLOSURE_TYPES           /* number of distinct closure types */
154
155 } StgClosureType;
156
157 /* The type flags provide quick access to certain properties of a closure. */
158
159 #define _HNF (1<<0)  /* head normal form?  */
160 #define _BTM (1<<1)  /* bitmap-style layout? */
161 #define _NS  (1<<2)  /* non-sparkable      */
162 #define _STA (1<<3)  /* static?            */
163 #define _THU (1<<4)  /* thunk?             */
164 #define _MUT (1<<5)  /* mutable?           */
165 #define _UPT (1<<6)  /* unpointed?         */
166 #define _SRT (1<<7)  /* has an SRT?        */
167
168 #define isSTATIC(flags)  ((flags)&_STA)
169 #define isMUTABLE(flags) ((flags) &_MUT)
170
171 #define closure_STATIC(closure)       (  get_itbl(closure)->flags & _STA)
172 #define closure_SHOULD_SPARK(closure) (!(get_itbl(closure)->flags & _NS))
173 #define closure_MUTABLE(closure)      (  get_itbl(closure)->flags & _MUT)
174 #define closure_UNPOINTED(closure)    (  get_itbl(closure)->flags & _UPT)
175
176 /*                                  HNF  BTM   NS  STA  THU MUT UPT SRT */
177                                                                     
178 #define FLAGS_CONSTR               (_HNF|     _NS                        )      
179 #define FLAGS_CONSTR_STATIC        (_HNF|     _NS|_STA                   )      
180 #define FLAGS_CONSTR_NOCAF_STATIC  (_HNF|     _NS|_STA                   )      
181 #define FLAGS_FUN                  (_HNF|     _NS|                  _SRT )      
182 #define FLAGS_FUN_STATIC           (_HNF|     _NS|_STA|             _SRT )      
183 #define FLAGS_THUNK                (     _BTM|         _THU|        _SRT )      
184 #define FLAGS_THUNK_STATIC         (     _BTM|    _STA|_THU|        _SRT )      
185 #define FLAGS_THUNK_SELECTOR       (     _BTM|         _THU|        _SRT )      
186 #define FLAGS_BCO                  (_HNF|     _NS                        )      
187 #define FLAGS_CAF_UNENTERED        0 /* Do we still use these? */
188 #define FLAGS_CAF_ENTERED          0
189 #define FLAGS_CAF_BLACKHOLE        (     _BTM|_NS|              _UPT     )
190 #define FLAGS_AP_UPD               (     _BTM|         _THU              )      
191 #define FLAGS_PAP                  (_HNF|     _NS                        )      
192 #define FLAGS_IND                  0
193 #define FLAGS_IND_OLDGEN           0
194 #define FLAGS_IND_PERM             0
195 #define FLAGS_IND_OLDGEN_PERM      0
196 #define FLAGS_IND_STATIC           (              _STA                   )      
197 #define FLAGS_EVACUATED            0
198 #define FLAGS_ARR_WORDS            (_HNF|     _NS|              _UPT     )      
199 #define FLAGS_MUT_ARR_WORDS        (_HNF|     _NS|         _MUT|_UPT     )      
200 #define FLAGS_MUT_ARR_PTRS         (_HNF|     _NS|         _MUT|_UPT     )      
201 #define FLAGS_MUT_ARR_PTRS_FROZEN  (_HNF|     _NS|         _MUT|_UPT     )      
202 #define FLAGS_MUT_VAR              (_HNF|     _NS|         _MUT|_UPT     )      
203 #define FLAGS_FOREIGN              (_HNF|     _NS|              _UPT     )      
204 #define FLAGS_STABLE_NAME          (_HNF|     _NS|              _UPT     )      
205 #define FLAGS_WEAK                 (_HNF|     _NS|              _UPT     )      
206 #define FLAGS_BLACKHOLE            (          _NS|              _UPT     )      
207 #define FLAGS_BLACKHOLE_BQ         (          _NS|         _MUT|_UPT     )      
208 #define FLAGS_MVAR                 (_HNF|     _NS|         _MUT|_UPT     )      
209 #define FLAGS_FETCH_ME             (_HNF|     _NS                        )      
210 #define FLAGS_TSO                  (_HNF|     _NS|         _MUT|_UPT     )
211 #define FLAGS_RET_BCO              (     _BTM                            )
212 #define FLAGS_RET_SMALL            (     _BTM|                       _SRT)
213 #define FLAGS_RET_VEC_SMALL        (     _BTM|                       _SRT)
214 #define FLAGS_RET_BIG              (                                 _SRT)
215 #define FLAGS_RET_VEC_BIG          (                                 _SRT)
216 #define FLAGS_RET_DYN              (                                 _SRT)
217 #define FLAGS_CATCH_FRAME          (     _BTM                            )
218 #define FLAGS_STOP_FRAME           (     _BTM                            )
219 #define FLAGS_SEQ_FRAME            (     _BTM                            )
220 #define FLAGS_UPDATE_FRAME         (     _BTM                            )
221
222 /* -----------------------------------------------------------------------------
223    Info Tables
224    -------------------------------------------------------------------------- */
225
226 /* A large bitmap.  Small 32-bit ones live in the info table, but sometimes
227  * 32 bits isn't enough and we have to generate a larger one.  (sizes
228  * differ for 64-bit machines.
229  */
230
231 typedef struct {
232   StgWord size;
233   StgWord bitmap[0];
234 } StgLargeBitmap;
235
236 /*
237  * Stuff describing the closure layout.  Well, actually, it might
238  * contain the selector index for a THUNK_SELECTOR.  If we're on a
239  * 64-bit architecture then we can enlarge some of these fields, since
240  * the union contains a pointer field.
241  */
242
243 typedef union {
244
245   StgWord bitmap;               /* bit pattern, 1 = pointer, 0 = non-pointer */
246   StgWord selector_offset;      /* used in THUNK_SELECTORs */
247   StgLargeBitmap* large_bitmap; /* pointer to large bitmap structure */
248
249 #if SIZEOF_VOID_P == 8
250   struct {
251     StgNat32 ptrs;              /* number of pointers     */
252     StgNat32 nptrs;             /* number of non-pointers */
253   } payload;
254 #else
255   struct {
256     StgNat16 ptrs;              /* number of pointers     */
257     StgNat16 nptrs;             /* number of non-pointers */
258   } payload;
259 #endif
260   
261 } StgClosureInfo;
262
263 /*
264  * Info tables.  All info tables are the same type, to simplify code
265  * generation.  However, the mangler removes any unused SRT fields
266  * from the asm to save space (convention: if srt_len is zero, or the
267  * type is a CONSTR_ type, then the SRT field isn't present.
268  */
269
270 typedef StgClosure* StgSRT[];
271
272 typedef struct _StgInfoTable {
273     StgSRT         *srt;        /* pointer to the SRT table */
274     StgParInfo      par;
275     StgProfInfo     prof;
276     StgDebugInfo    debug;
277     StgClosureInfo  layout;     /* closure layout info (pointer-sized) */
278 #if SIZEOF_VOID_P == 8
279     StgNat16        flags;      /* }                                   */
280     StgClosureType  type : 16;  /* } These 4 elements fit into 64 bits */
281     StgNat32        srt_len;    /* }                                   */
282 #else
283     StgNat8         flags;      /* }                                   */
284     StgClosureType  type : 8;   /* } These 4 elements fit into 32 bits */
285     StgNat16        srt_len;    /* }                                   */
286 #endif
287 #if USE_MINIINTERPRETER
288     StgFunPtr       (*vector)[];
289     StgFunPtr       entry;
290 #else
291     StgCode         code[0];
292 #endif
293 } StgInfoTable;
294
295 #endif /* INFOTABLES_H */