[project @ 2000-01-12 15:15:17 by simonmar]
[ghc-hetmet.git] / ghc / includes / InfoMacros.h
1 /* ----------------------------------------------------------------------------
2  * $Id: InfoMacros.h,v 1.8 1999/11/30 11:44:32 simonmar Exp $
3  * 
4  * (c) The GHC Team, 1998-1999
5  *
6  * Macros for building and deconstructing info tables.
7  *
8  * -------------------------------------------------------------------------- */
9
10 #ifndef INFOMACROS_H
11 #define INFOMACROS_H
12
13 #define STD_INFO(type_)                         \
14                 srt : 0,                        \
15                 srt_len : 0,                    \
16                 type : type_
17
18 #define SRT_INFO(type_,srt_,srt_off_,srt_len_)                  \
19                 srt : (StgSRT *)((StgClosure **)srt_+srt_off_), \
20                 srt_len : srt_len_,                             \
21                 type : type_
22
23 #define CONSTR_INFO(type_,tag_)                 \
24                 srt : 0,                        \
25                 srt_len : tag_,                 \
26                 type : type_
27
28 #ifdef USE_MINIINTERPRETER
29 #define INIT_VECTOR {}
30 #else
31 #define INIT_VECTOR
32 #endif
33
34 /* function/thunk info tables --------------------------------------------- */
35
36 #define \
37 INFO_TABLE_SRT(info,                            /* info-table label */  \
38                entry,                           /* entry code label */  \
39                ptrs, nptrs,                     /* closure layout info */\
40                srt_, srt_off_, srt_len_,        /* SRT info */          \
41                type,                            /* closure type */      \
42                info_class, entry_class,         /* C storage classes */ \
43                prof_descr, prof_type)           /* profiling info */    \
44         entry_class(entry);                                             \
45         info_class INFO_TBL_CONST StgInfoTable info = {                 \
46                 layout : { payload : {ptrs,nptrs} },                    \
47                 SRT_INFO(type,srt_,srt_off_,srt_len_),                  \
48                 INIT_ENTRY(entry),                                      \
49                 INIT_VECTOR                                             \
50         }
51
52
53 /* direct-return address info tables  --------------------------------------*/
54
55 #define                                                                 \
56 INFO_TABLE_SRT_BITMAP(info, entry, bitmap_, srt_, srt_off_, srt_len_,   \
57                       type, info_class, entry_class,                    \
58                       prof_descr, prof_type)                            \
59         entry_class(entry);                                             \
60         info_class INFO_TBL_CONST StgInfoTable info = {                 \
61                 layout : { bitmap : (StgWord32)bitmap_ },               \
62                 SRT_INFO(type,srt_,srt_off_,srt_len_),                  \
63                 INIT_ENTRY(entry),                                      \
64                 INIT_VECTOR                                             \
65         }
66
67 /* info-table without an SRT -----------------------------------------------*/
68
69 #define                                                 \
70 INFO_TABLE(info, entry, ptrs, nptrs, type, info_class,  \
71            entry_class, prof_descr, prof_type)          \
72         entry_class(entry);                             \
73         info_class INFO_TBL_CONST StgInfoTable info = { \
74                 layout : { payload : {ptrs,nptrs} },    \
75                 STD_INFO(type),                         \
76                 INIT_ENTRY(entry),                      \
77                 INIT_VECTOR                             \
78         }
79
80 /* special selector-thunk info table ---------------------------------------*/
81
82 #define                                                 \
83 INFO_TABLE_SELECTOR(info, entry, offset, info_class,    \
84                     entry_class, prof_descr, prof_type) \
85         entry_class(entry);                             \
86         info_class INFO_TBL_CONST StgInfoTable info = { \
87                 layout : { selector_offset : offset },  \
88                 STD_INFO(THUNK_SELECTOR),               \
89                 INIT_ENTRY(entry),                      \
90                 INIT_VECTOR                             \
91         }
92
93 /* constructor info table --------------------------------------------------*/
94
95 #define \
96 INFO_TABLE_CONSTR(info, entry, ptrs, nptrs, tag_,type_,info_class,      \
97                   entry_class, prof_descr, prof_type)                   \
98         entry_class(entry);                                             \
99         info_class INFO_TBL_CONST StgInfoTable info = {                 \
100                 layout : { payload : {ptrs,nptrs} },                    \
101                 CONSTR_INFO(type_,tag_),                                \
102                 INIT_ENTRY(entry),                                      \
103                 INIT_VECTOR                                             \
104         }
105
106 #define constrTag(con) (get_itbl(con)->srt_len)
107
108 /* return-vectors ----------------------------------------------------------*/
109
110 /* vectored-return info tables have the vector slammed up against the
111  * start of the info table.
112  *
113  * A vectored-return address always has an SRT and a bitmap-style
114  * layout field, so we only need one macro for these.
115  */
116
117 #ifdef TABLES_NEXT_TO_CODE
118
119 typedef struct {
120   StgFunPtr vec[2];
121   StgInfoTable i;
122 } vec_info_2;
123
124 typedef struct {
125   StgFunPtr vec[3];
126   StgInfoTable i;
127 } vec_info_3;
128
129 typedef struct {
130   StgFunPtr vec[4];
131   StgInfoTable i;
132 } vec_info_4;
133
134 typedef struct {
135   StgFunPtr vec[5];
136   StgInfoTable i;
137 } vec_info_5;
138
139 typedef struct {
140   StgFunPtr vec[6];
141   StgInfoTable i;
142 } vec_info_6;
143
144 typedef struct {
145   StgFunPtr vec[7];
146   StgInfoTable i;
147 } vec_info_7;
148
149 typedef struct {
150   StgFunPtr vec[8];
151   StgInfoTable i;
152 } vec_info_8;
153
154 #define VEC_INFO_2(info,bitmap_,srt_,srt_off_,srt_len_,         \
155                    type, info_class,                            \
156                    alt_1, alt_2)                                \
157         info_class INFO_TBL_CONST vec_info_2 info = {           \
158                 { alt_2, alt_1 },                               \
159                 i : {                                           \
160                    layout : { bitmap : (StgWord32)bitmap_ },    \
161                    SRT_INFO(type,srt_,srt_off_,srt_len_)        \
162                 }                                               \
163         }
164
165 #define VEC_INFO_3(info,bitmap_,srt_,srt_off_,srt_len_,         \
166                    type, info_class,                            \
167                    alt_1, alt_2, alt_3                          \
168                   )                                             \
169         info_class INFO_TBL_CONST vec_info_3 info = {           \
170                 { alt_3, alt_2, alt_1 },                        \
171                 i : {                                           \
172                    layout : { bitmap : (StgWord32)bitmap_ },    \
173                    SRT_INFO(type,srt_,srt_off_,srt_len_)        \
174                 }                                               \
175         }
176
177 #define VEC_INFO_4(info,bitmap_,srt_,srt_off_,srt_len_,         \
178                    type, info_class,                            \
179                    alt_1, alt_2, alt_3, alt_4                   \
180                   )                                             \
181         info_class INFO_TBL_CONST vec_info_4 info = {           \
182                 { alt_4, alt_3, alt_2, alt_1 },                 \
183                 i : {                                           \
184                    layout : { bitmap : (StgWord32)bitmap_ },    \
185                    SRT_INFO(type,srt_,srt_off_,srt_len_)        \
186                 }                                               \
187         }
188
189 #define VEC_INFO_5(info,bitmap_,srt_,srt_off_,srt_len_,         \
190                    type, info_class,                            \
191                    alt_1, alt_2, alt_3, alt_4,                  \
192                    alt_5                                        \
193                   )                                             \
194         info_class INFO_TBL_CONST vec_info_5 info = {           \
195                 { alt_5, alt_4, alt_3, alt_2,                   \
196                   alt_1 },                                      \
197                 i : {                                           \
198                    layout : { bitmap : (StgWord32)bitmap_ },    \
199                    SRT_INFO(type,srt_,srt_off_,srt_len_)        \
200                 }                                               \
201         }
202
203 #define VEC_INFO_6(info,bitmap_,srt_,srt_off_,srt_len_,         \
204                    type, info_class,                            \
205                    alt_1, alt_2, alt_3, alt_4,                  \
206                    alt_5, alt_6                                 \
207                   )                                             \
208         info_class INFO_TBL_CONST vec_info_6 info = {           \
209                 { alt_6, alt_5, alt_4, alt_3,                   \
210                   alt_2, alt_1 },                               \
211                 i : {                                           \
212                    layout : { bitmap : (StgWord32)bitmap_ },    \
213                    SRT_INFO(type,srt_,srt_off_,srt_len_)        \
214                 }                                               \
215         }
216
217 #define VEC_INFO_7(info,bitmap_,srt_,srt_off_,srt_len_,         \
218                    type, info_class,                            \
219                    alt_1, alt_2, alt_3, alt_4,                  \
220                    alt_5, alt_6, alt_7                          \
221                   )                                             \
222         info_class INFO_TBL_CONST vec_info_7 info = {           \
223                 { alt_7, alt_6, alt_5, alt_4,                   \
224                   alt_3, alt_2, alt_1 },                        \
225                 i : {                                           \
226                    layout : { bitmap : (StgWord32)bitmap_ },    \
227                    SRT_INFO(type,srt_,srt_off_,srt_len_)        \
228                 }                                               \
229         }
230
231 #define VEC_INFO_8(info,bitmap_,srt_,srt_off_,srt_len_,         \
232                    type, info_class,                            \
233                    alt_1, alt_2, alt_3, alt_4,                  \
234                    alt_5, alt_6, alt_7, alt_8                   \
235                   )                                             \
236         info_class INFO_TBL_CONST vec_info_8 info = {           \
237                 { alt_8, alt_7, alt_6, alt_5,                   \
238                   alt_4, alt_3, alt_2, alt_1 },                 \
239                 i : {                                           \
240                    layout : { bitmap : (StgWord32)bitmap_ },    \
241                    SRT_INFO(type,srt_,srt_off_,srt_len_)        \
242                 }                                               \
243         }
244
245
246 #else
247
248 /* We have to define these structure to work around a bug in gcc: if we
249  * try to initialise the vector directly (it's defined as a zero-length
250  * array tacked on the end of the info table structor), then gcc silently
251  * throws away our vector table sometimes.
252  */
253
254 typedef struct {
255   StgInfoTable i;
256   StgFunPtr vec[2];
257 } vec_info_2;
258
259 typedef struct {
260   StgInfoTable i;
261   StgFunPtr vec[3];
262 } vec_info_3;
263
264 typedef struct {
265   StgInfoTable i;
266   StgFunPtr vec[4];
267 } vec_info_4;
268
269 typedef struct {
270   StgInfoTable i;
271   StgFunPtr vec[5];
272 } vec_info_5;
273
274 typedef struct {
275   StgInfoTable i;
276   StgFunPtr vec[6];
277 } vec_info_6;
278
279 typedef struct {
280   StgInfoTable i;
281   StgFunPtr vec[7];
282 } vec_info_7;
283
284 typedef struct {
285   StgInfoTable i;
286   StgFunPtr vec[8];
287 } vec_info_8;
288
289 #define VEC_INFO_2(info,bitmap_,srt_,srt_off_,srt_len_,         \
290                    type, info_class,                            \
291                    alt_1, alt_2)                                \
292         info_class INFO_TBL_CONST vec_info_2 info = {           \
293                 i : { layout : { bitmap : (StgWord32)bitmap_ }, \
294                       SRT_INFO(type,srt_,srt_off_,srt_len_),    \
295                       INIT_ENTRY(NULL),                         \
296                 },                                              \
297                 vec : { alt_1, alt_2 }                          \
298         }
299
300 #define VEC_INFO_3(info,bitmap_,srt_,srt_off_,srt_len_,         \
301                    type, info_class,                            \
302                    alt_1, alt_2, alt_3                          \
303                   )                                             \
304         info_class INFO_TBL_CONST vec_info_3 info = {           \
305                 i : { layout : { bitmap : (StgWord32)bitmap_ }, \
306                       SRT_INFO(type,srt_,srt_off_,srt_len_),    \
307                       INIT_ENTRY(NULL),                         \
308                 },                                              \
309                 vec : { alt_1, alt_2, alt_3 }                   \
310         }
311
312 #define VEC_INFO_4(info,bitmap_,srt_,srt_off_,srt_len_,         \
313                    type, info_class,                            \
314                    alt_1, alt_2, alt_3, alt_4                   \
315                   )                                             \
316         info_class INFO_TBL_CONST vec_info_4 info = {           \
317                 i : { layout : { bitmap : (StgWord32)bitmap_ }, \
318                       SRT_INFO(type,srt_,srt_off_,srt_len_),    \
319                       INIT_ENTRY(NULL),                         \
320                 },                                              \
321                 vec : { alt_1, alt_2, alt_3, alt_4 }            \
322         }
323
324 #define VEC_INFO_5(info,bitmap_,srt_,srt_off_,srt_len_,         \
325                    type, info_class,                            \
326                    alt_1, alt_2, alt_3, alt_4,                  \
327                    alt_5                                        \
328                   )                                             \
329         info_class INFO_TBL_CONST vec_info_5 info = {           \
330                 i : { layout : { bitmap : (StgWord32)bitmap_ }, \
331                       SRT_INFO(type,srt_,srt_off_,srt_len_),    \
332                       INIT_ENTRY(NULL),                         \
333                 },                                              \
334                 vec : { alt_1, alt_2, alt_3, alt_4,             \
335                         alt_5 }                                 \
336         }
337
338 #define VEC_INFO_6(info,bitmap_,srt_,srt_off_,srt_len_,         \
339                    type, info_class,                            \
340                    alt_1, alt_2, alt_3, alt_4,                  \
341                    alt_5, alt_6                                 \
342                   )                                             \
343         info_class INFO_TBL_CONST vec_info_6 info = {           \
344                 i : { layout : { bitmap : (StgWord32)bitmap_ }, \
345                       SRT_INFO(type,srt_,srt_off_,srt_len_),    \
346                       INIT_ENTRY(NULL),                         \
347                 },                                              \
348                 vec : { alt_1, alt_2, alt_3, alt_4,             \
349                         alt_5, alt_6 }                          \
350         }
351
352 #define VEC_INFO_7(info,bitmap_,srt_,srt_off_,srt_len_,         \
353                    type, info_class,                            \
354                    alt_1, alt_2, alt_3, alt_4,                  \
355                    alt_5, alt_6, alt_7                          \
356                   )                                             \
357         info_class INFO_TBL_CONST vec_info_7 info = {           \
358                 i : { layout : { bitmap : (StgWord32)bitmap_ }, \
359                       SRT_INFO(type,srt_,srt_off_,srt_len_),    \
360                       INIT_ENTRY(NULL),                         \
361                 },                                              \
362                 vec : { alt_1, alt_2, alt_3, alt_4,             \
363                         alt_5, alt_6, alt_7 }                   \
364         }
365
366 #define VEC_INFO_8(info,bitmap_,srt_,srt_off_,srt_len_,         \
367                    type, info_class,                            \
368                    alt_1, alt_2, alt_3, alt_4,                  \
369                    alt_5, alt_6, alt_7, alt_8                   \
370                   )                                             \
371         info_class INFO_TBL_CONST vec_info_8 info = {           \
372                 i : { layout : { bitmap : (StgWord32)bitmap_ }, \
373                       SRT_INFO(type,srt_,srt_off_,srt_len_),    \
374                       INIT_ENTRY(NULL),                         \
375                 },                                              \
376                 vec : { alt_1, alt_2, alt_3, alt_4,             \
377                         alt_5, alt_6, alt_7, alt_8 }            \
378         }
379
380 #endif /* TABLES_NEXT_TO_CODE */
381
382 /* For polymorphic activation records, we need both a direct return
383  * address and a return vector:
384  */
385
386 typedef vec_info_8 StgPolyInfoTable;
387
388 #ifndef TABLES_NEXT_TO_CODE
389
390 #define VEC_POLY_INFO_TABLE(nm, bitmap_,                        \
391                            srt_, srt_off_, srt_len_,            \
392                            type, info_class, entry_class        \
393                            )                                    \
394   info_class INFO_TBL_CONST vec_info_8 nm##_info = {            \
395                 i : { layout : { bitmap : (StgWord32)bitmap_ }, \
396                       SRT_INFO(type,srt_,srt_off_,srt_len_),    \
397                       INIT_ENTRY(nm##_entry),                   \
398                       INIT_VECTOR                               \
399                 },                                              \
400                 vec : {                                         \
401                         (F_) nm##_0_entry,                      \
402                         (F_) nm##_1_entry,                      \
403                         (F_) nm##_2_entry,                      \
404                         (F_) nm##_3_entry,                      \
405                         (F_) nm##_4_entry,                      \
406                         (F_) nm##_5_entry,                      \
407                         (F_) nm##_6_entry,                      \
408                         (F_) nm##_7_entry                       \
409                 }                                               \
410             }
411 #else
412
413 #define VEC_POLY_INFO_TABLE(nm, bitmap_,                        \
414                            srt_, srt_off_, srt_len_,            \
415                            type, info_class, entry_class        \
416                            )                                    \
417         info_class INFO_TBL_CONST vec_info_8 nm##_info = {      \
418                 {                                               \
419                         (F_) nm##_7_entry,                      \
420                         (F_) nm##_6_entry,                      \
421                         (F_) nm##_5_entry,                      \
422                         (F_) nm##_4_entry,                      \
423                         (F_) nm##_3_entry,                      \
424                         (F_) nm##_2_entry,                      \
425                         (F_) nm##_1_entry,                      \
426                         (F_) nm##_0_entry                       \
427                 },                                              \
428                 i : {                                           \
429                    layout : { bitmap : (StgWord32)bitmap_ },    \
430                    SRT_INFO(type,srt_,srt_off_,srt_len_),       \
431                    INIT_ENTRY(nm##_entry)                       \
432                 }                                               \
433         }
434
435 #endif
436
437 #define SRT(lbl) \
438   static const StgSRT lbl = {
439
440 #define BITMAP(lbl,size) \
441   static const StgLargeBitmap lbl = { size, {
442
443 /* DLL_SRT_ENTRY is used on the Win32 side when filling initialising
444    an entry in an SRT table with a reference to a closure that's
445    living in a DLL. See elsewhere for reasons as to why we need
446    to distinguish these kinds of references.
447    (ToDo: fill in a more precise href.)
448 */
449 #ifdef HAVE_WIN32_DLL_SUPPORT
450 #define DLL_SRT_ENTRY(x) ((StgClosure*)(((char*)&DLL_IMPORT_DATA_VAR(x)) + 1))
451 #else
452 #define DLL_SRT_ENTRY(x) no-can-do
453 #endif
454
455 #endif /* INFOMACROS_H */