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