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