[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / includes / InfoMacros.h
1 /* ----------------------------------------------------------------------------
2  * $Id: InfoMacros.h,v 1.2 1998/12/02 13:21:09 simonm Exp $
3  * 
4  * Macros for building and deconstructing info tables.
5  *
6  * -------------------------------------------------------------------------- */
7
8 #ifndef INFOMACROS_H
9 #define INFOMACROS_H
10
11 #define STD_INFO(type_)                         \
12                 srt : 0,                        \
13                 srt_len : 0,                    \
14                 type : type_,                   \
15                 flags: FLAGS_##type_
16
17 #define SRT_INFO(type_,srt_,srt_off_,srt_len_)                  \
18                 srt : (StgSRT *)((StgClosure **)srt_+srt_off_), \
19                 srt_len : srt_len_,                             \
20                 type : type_,                                   \
21                 flags: FLAGS_##type_
22
23 /* function/thunk info tables --------------------------------------------- */
24
25 #define \
26 INFO_TABLE_SRT(info,                            /* info-table label */  \
27                entry,                           /* entry code label */  \
28                ptrs, nptrs,                     /* closure layout info */\
29                srt_, srt_off_, srt_len_,        /* SRT info */          \
30                type,                            /* closure type */      \
31                info_class, entry_class,         /* C storage classes */ \
32                prof_descr, prof_type)           /* profiling info */    \
33         entry_class(entry);                                             \
34         info_class StgInfoTable info = {                                \
35                 layout : { payload : {ptrs,nptrs} },                    \
36                 SRT_INFO(type,srt_,srt_off_,srt_len_),                  \
37                 INIT_ENTRY(entry)                                       \
38         }
39
40
41 /* direct-return address info tables  --------------------------------------*/
42
43 #define \
44 INFO_TABLE_SRT_BITMAP(info, entry, bitmap_, srt_, srt_off_, srt_len_, \
45                       type, info_class, entry_class,    \
46                       prof_descr, prof_type)            \
47         entry_class(entry);                             \
48         info_class StgInfoTable info = {                \
49                 layout : { bitmap : (StgNat32)bitmap_ },\
50                 SRT_INFO(type,srt_,srt_off_,srt_len_),  \
51                 INIT_ENTRY(entry)                       \
52         }
53
54 /* info-table without an SRT -----------------------------------------------*/
55
56 #define \
57 INFO_TABLE(info, entry, ptrs, nptrs, type, info_class, \
58            entry_class, prof_descr, prof_type) \
59         entry_class(entry);                             \
60         info_class StgInfoTable info = {                \
61                 layout : { payload : {ptrs,nptrs} },    \
62                 STD_INFO(type),                         \
63                 INIT_ENTRY(entry)                       \
64         }
65
66 /* special selector-thunk info table ---------------------------------------*/
67
68 #define \
69 INFO_TABLE_SELECTOR(info, entry, offset, info_class, \
70                     entry_class, prof_descr, prof_type) \
71         entry_class(entry);                                     \
72         info_class StgInfoTable info = {                        \
73                 layout : { selector_offset : offset },  \
74                 STD_INFO(THUNK_SELECTOR),               \
75                 INIT_ENTRY(entry)                       \
76         }
77
78 /* constructor info table --------------------------------------------------*/
79
80 #define \
81 INFO_TABLE_CONSTR(info, entry, ptrs, nptrs, tag_,type_,info_class, \
82                   entry_class, prof_descr, prof_type) \
83         entry_class(entry);                             \
84         info_class StgInfoTable info = {                \
85                 layout : { payload : {ptrs,nptrs} },    \
86                 srt_len : tag_,                         \
87                 type : type_,                           \
88                 flags : FLAGS_##type_,                  \
89                 INIT_ENTRY(entry)                       \
90         }
91
92 #define constrTag(con) (get_itbl(con)->srt_len)
93
94 /* return-vectors ----------------------------------------------------------*/
95
96 /* vectored-return info tables have the vector slammed up against the
97  * start of the info table.
98  *
99  * A vectored-return address always has an SRT and a bitmap-style
100  * layout field, so we only need one macro for these.
101  */
102
103 typedef struct {
104   StgFunPtr vec[2];
105   StgInfoTable i;
106 } vec_info_2;
107
108 typedef struct {
109   StgFunPtr vec[3];
110   StgInfoTable i;
111 } vec_info_3;
112
113 typedef struct {
114   StgFunPtr vec[4];
115   StgInfoTable i;
116 } vec_info_4;
117
118 typedef struct {
119   StgFunPtr vec[5];
120   StgInfoTable i;
121 } vec_info_5;
122
123 typedef struct {
124   StgFunPtr vec[6];
125   StgInfoTable i;
126 } vec_info_6;
127
128 typedef struct {
129   StgFunPtr vec[7];
130   StgInfoTable i;
131 } vec_info_7;
132
133 typedef struct {
134   StgFunPtr vec[8];
135   StgInfoTable i;
136 } vec_info_8;
137
138 #define VEC_INFO_TABLE(bitmap_,srt_,srt_off_,srt_len_,type)     \
139         i : {                                                   \
140                 layout : { bitmap : (StgNat32)bitmap_ },        \
141                 SRT_INFO(type,srt_,srt_off_,srt_len_)           \
142         }
143
144 /* For polymorphic activation records, we need both a direct return
145  * address and a return vector:
146  */
147
148 #ifdef USE_MINIINTERPRETER
149 typedef StgInfoTable StgPolyInfoTable;
150 #define POLY_VEC(nm) \
151   {                                                     \
152         (F_) nm##_0_entry,                              \
153         (F_) nm##_1_entry,                              \
154         (F_) nm##_2_entry,                              \
155         (F_) nm##_3_entry,                              \
156         (F_) nm##_4_entry,                              \
157         (F_) nm##_5_entry,                              \
158         (F_) nm##_6_entry,                              \
159         (F_) nm##_7_entry                               \
160    }
161 #define VEC_POLY_INFO_TABLE(nm,bitmap_,srt_,srt_off_,srt_len_,type) \
162   StgFunPtr nm##_vec[8] = POLY_VEC(nm);                         \
163   const StgInfoTable nm##_info = {                                      \
164                 layout : { bitmap : (StgNat32)bitmap_ },        \
165                 SRT_INFO(type,srt_,srt_off_,srt_len_),          \
166                 vector : &nm##_vec,                              \
167                 INIT_ENTRY(nm##_entry)                          \
168             }
169 #else
170 typedef vec_info_8 StgPolyInfoTable;
171 #define POLY_VEC(nm) \
172   {                                                     \
173         (F_) nm##_7_entry,                              \
174         (F_) nm##_6_entry,                              \
175         (F_) nm##_5_entry,                              \
176         (F_) nm##_4_entry,                              \
177         (F_) nm##_3_entry,                              \
178         (F_) nm##_2_entry,                              \
179         (F_) nm##_1_entry,                              \
180         (F_) nm##_0_entry                               \
181    }
182 #define VEC_POLY_INFO_TABLE(nm,bitmap_,srt_,srt_off_,srt_len_,type) \
183   const vec_info_8 nm##_info = {                                \
184         vec : POLY_VEC(nm),                                     \
185         i : {                                                   \
186                 layout : { bitmap : (StgNat32)bitmap_ },        \
187                 SRT_INFO(type,srt_,srt_off_,srt_len_),          \
188                 INIT_ENTRY(nm##_entry)                          \
189             }                                                   \
190   }
191 #endif
192
193 #define SRT(lbl) \
194   static const StgSRT lbl = {
195
196 #define BITMAP(lbl,size) \
197   static const StgLargeBitmap lbl = { size, {
198
199 #endif /* INFOMACROS_H */