[project @ 1999-03-15 16:30:24 by simonm]
[ghc-hetmet.git] / ghc / includes / InfoMacros.h
1 /* ----------------------------------------------------------------------------
2  * $Id: InfoMacros.h,v 1.5 1999/03/15 16:30:25 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
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 /* 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 : (StgWord32)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                 INIT_ENTRY(entry)                       \
89         }
90
91 #define constrTag(con) (get_itbl(con)->srt_len)
92
93 /* return-vectors ----------------------------------------------------------*/
94
95 /* vectored-return info tables have the vector slammed up against the
96  * start of the info table.
97  *
98  * A vectored-return address always has an SRT and a bitmap-style
99  * layout field, so we only need one macro for these.
100  */
101
102 typedef struct {
103   StgFunPtr vec[2];
104   StgInfoTable i;
105 } vec_info_2;
106
107 typedef struct {
108   StgFunPtr vec[3];
109   StgInfoTable i;
110 } vec_info_3;
111
112 typedef struct {
113   StgFunPtr vec[4];
114   StgInfoTable i;
115 } vec_info_4;
116
117 typedef struct {
118   StgFunPtr vec[5];
119   StgInfoTable i;
120 } vec_info_5;
121
122 typedef struct {
123   StgFunPtr vec[6];
124   StgInfoTable i;
125 } vec_info_6;
126
127 typedef struct {
128   StgFunPtr vec[7];
129   StgInfoTable i;
130 } vec_info_7;
131
132 typedef struct {
133   StgFunPtr vec[8];
134   StgInfoTable i;
135 } vec_info_8;
136
137 #define VEC_INFO_TABLE(bitmap_,srt_,srt_off_,srt_len_,type)     \
138         i : {                                                   \
139                 layout : { bitmap : (StgWord32)bitmap_ },       \
140                 SRT_INFO(type,srt_,srt_off_,srt_len_)           \
141         }
142
143 /* For polymorphic activation records, we need both a direct return
144  * address and a return vector:
145  */
146
147 #ifdef USE_MINIINTERPRETER
148 typedef StgInfoTable StgPolyInfoTable;
149 #define POLY_VEC(nm) \
150   {                                                     \
151         (F_) nm##_0_entry,                              \
152         (F_) nm##_1_entry,                              \
153         (F_) nm##_2_entry,                              \
154         (F_) nm##_3_entry,                              \
155         (F_) nm##_4_entry,                              \
156         (F_) nm##_5_entry,                              \
157         (F_) nm##_6_entry,                              \
158         (F_) nm##_7_entry                               \
159    }
160 #define VEC_POLY_INFO_TABLE(nm,bitmap_,srt_,srt_off_,srt_len_,type) \
161   StgFunPtr nm##_vec[8] = POLY_VEC(nm);                         \
162   const StgInfoTable nm##_info = {                                      \
163                 layout : { bitmap : (StgWord32)bitmap_ },       \
164                 SRT_INFO(type,srt_,srt_off_,srt_len_),          \
165                 vector : &nm##_vec,                              \
166                 INIT_ENTRY(nm##_entry)                          \
167             }
168 #else
169 typedef vec_info_8 StgPolyInfoTable;
170 #define POLY_VEC(nm) \
171   {                                                     \
172         (F_) nm##_7_entry,                              \
173         (F_) nm##_6_entry,                              \
174         (F_) nm##_5_entry,                              \
175         (F_) nm##_4_entry,                              \
176         (F_) nm##_3_entry,                              \
177         (F_) nm##_2_entry,                              \
178         (F_) nm##_1_entry,                              \
179         (F_) nm##_0_entry                               \
180    }
181 #define VEC_POLY_INFO_TABLE(nm,bitmap_,srt_,srt_off_,srt_len_,type) \
182   const vec_info_8 nm##_info = {                                \
183         vec : POLY_VEC(nm),                                     \
184         i : {                                                   \
185                 layout : { bitmap : (StgWord32)bitmap_ },       \
186                 SRT_INFO(type,srt_,srt_off_,srt_len_),          \
187                 INIT_ENTRY(nm##_entry)                          \
188             }                                                   \
189   }
190 #endif
191
192 #define SRT(lbl) \
193   static const StgSRT lbl = {
194
195 #define BITMAP(lbl,size) \
196   static const StgLargeBitmap lbl = { size, {
197
198 /* DLL_SRT_ENTRY is used on the Win32 side when filling initialising
199    an entry in an SRT table with a reference to a closure that's
200    living in a DLL. See elsewhere for reasons as to why we need
201    to distinguish these kinds of references.
202    (ToDo: fill in a more precise href.)
203 */
204 #ifdef HAVE_WIN32_DLL_SUPPORT
205 #define DLL_SRT_ENTRY(x) ((StgClosure*)(((char*)&DLL_IMPORT_DATA_VAR(x)) + 1))
206 #else
207 #define DLL_SRT_ENTRY(x) no-can-do
208 #endif
209
210 #endif /* INFOMACROS_H */