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