[project @ 1999-06-25 09:13:37 by simonmar]
[ghc-hetmet.git] / ghc / includes / InfoTables.h
1 /* ----------------------------------------------------------------------------
2  * $Id: InfoTables.h,v 1.16 1999/06/25 09:13:37 simonmar Exp $
3  * 
4  * (c) The GHC Team, 1998-1999
5  *
6  * Info Tables
7  *
8  * -------------------------------------------------------------------------- */
9
10 #ifndef INFOTABLES_H
11 #define INFOTABLES_H
12
13 /* -----------------------------------------------------------------------------
14    Profiling info
15    -------------------------------------------------------------------------- */
16
17 #ifdef PROFILING
18
19 #define PROF_INFO_WORDS n
20
21 typedef struct {
22   /* nothing yet */
23 } StgProfInfo;
24
25 #else /* !PROFILING */
26
27 #define PROF_INFO_WORDS 0
28
29 typedef struct {
30   /* empty */
31 } StgProfInfo;
32
33 #endif /* PROFILING */
34
35 /* -----------------------------------------------------------------------------
36    Parallelism info
37    -------------------------------------------------------------------------- */
38
39 #ifdef PAR
40
41 #define PAR_INFO_WORDS 0
42
43 typedef struct {
44        /* empty */
45 } StgParInfo;
46
47 #else /* !PAR */
48
49 #define PAR_INFO_WORDS 0
50
51 typedef struct {
52         /* empty */
53 } StgParInfo;
54
55 #endif /* PAR */
56
57 /* -----------------------------------------------------------------------------
58    Debugging info
59    -------------------------------------------------------------------------- */
60
61 #ifdef DEBUG_CLOSURE
62
63 #define DEBUG_INFO_WORDS n
64
65 typedef struct {
66         ... whatever ...
67 } StgDebugInfo;
68
69 #else /* !DEBUG_CLOSURE */
70
71 #define DEBUG_INFO_WORDS 0
72
73 typedef struct {
74         /* empty */
75 } StgDebugInfo;
76
77 #endif /* DEBUG_CLOSURE */
78
79 /* The type flags provide quick access to certain properties of a closure. */
80
81 #define _HNF (1<<0)  /* head normal form?  */
82 #define _BTM (1<<1)  /* bitmap-style layout? */
83 #define _NS  (1<<2)  /* non-sparkable      */
84 #define _STA (1<<3)  /* static?            */
85 #define _THU (1<<4)  /* thunk?             */
86 #define _MUT (1<<5)  /* mutable?           */
87 #define _UPT (1<<6)  /* unpointed?         */
88 #define _SRT (1<<7)  /* has an SRT?        */
89
90 #define isSTATIC(flags)    ((flags) &_STA)
91 #define isMUTABLE(flags)   ((flags) &_MUT)
92 #define isBITMAP(flags)    ((flags) &_BTM)
93 #define isTHUNK(flags)     ((flags) &_THU)
94 #define isUNPOINTED(flags) ((flags) &_UPT)
95 #define hasSRT(flags)      ((flags) &_SRT)
96
97 extern StgWord16 closure_flags[];
98
99 #define closureFlags(c)         (closure_flags[get_itbl(c)->type])
100
101 #define closure_STATIC(c)       (  closureFlags(c) & _STA)
102 #define closure_SHOULD_SPARK(c) (!(closureFlags(c) & _NS))
103 #define closure_MUTABLE(c)      (  closureFlags(c) & _MUT)
104 #define closure_UNPOINTED(c)    (  closureFlags(c) & _UPT)
105
106
107 /* -----------------------------------------------------------------------------
108    Info Tables
109    -------------------------------------------------------------------------- */
110
111 /* A large bitmap.  Small 32-bit ones live in the info table, but sometimes
112  * 32 bits isn't enough and we have to generate a larger one.  (sizes
113  * differ for 64-bit machines.
114  */
115
116 typedef struct {
117   StgWord size;
118   StgWord bitmap[0];
119 } StgLargeBitmap;
120
121 /*
122  * Stuff describing the closure layout.  Well, actually, it might
123  * contain the selector index for a THUNK_SELECTOR.  If we're on a
124  * 64-bit architecture then we can enlarge some of these fields, since
125  * the union contains a pointer field.
126  */
127
128 typedef union {
129 #if SIZEOF_VOID_P == 8
130   struct {
131     StgWord32 ptrs;             /* number of pointers     */
132     StgWord32 nptrs;            /* number of non-pointers */
133   } payload;
134 #else
135   struct {
136     StgWord16 ptrs;             /* number of pointers     */
137     StgWord16 nptrs;            /* number of non-pointers */
138   } payload;
139
140   StgWord bitmap;               /* bit pattern, 1 = pointer, 0 = non-pointer */
141   StgWord selector_offset;      /* used in THUNK_SELECTORs */
142   StgLargeBitmap* large_bitmap; /* pointer to large bitmap structure */
143
144 #endif
145   
146 } StgClosureInfo;
147
148 /*
149  * Info tables.  All info tables are the same type, to simplify code
150  * generation.  However, the mangler removes any unused SRT fields
151  * from the asm to save space (convention: if srt_len is zero, or the
152  * type is a CONSTR_ type, then the SRT field isn't present.
153  */
154
155 typedef StgClosure* StgSRT[];
156
157 typedef struct _StgInfoTable {
158     StgSRT         *srt;        /* pointer to the SRT table */
159 #ifdef PAR
160     StgParInfo      par;
161 #endif
162 #ifdef PROFILING
163   /* StgProfInfo     prof; */
164 #endif
165 #ifdef DEBUG_CLOSURE
166     StgDebugInfo    debug;
167 #endif
168     StgClosureInfo  layout;     /* closure layout info (pointer-sized) */
169 #if SIZEOF_VOID_P == 8
170     StgWord32       type;       /* } These 2 elements fit into 64 bits */
171     StgWord32       srt_len;    /* }                                   */
172 #else
173     StgWord         type : 16;  /* } These 2 elements fit into 32 bits */
174     StgWord         srt_len : 16; /* }                                   */
175 #endif
176 #ifdef TABLES_NEXT_TO_CODE
177     StgCode         code[0];
178 #else
179     StgFunPtr       entry;
180     StgFunPtr       vector[0];
181 #endif
182 } StgInfoTable;
183
184 /* Info tables are read-only, therefore we uniformly declare them with
185  * C's const attribute.  This isn't just a nice thing to do: it's
186  * necessary because the garbage collector has to distinguish between 
187  * closure pointers and info table pointers when traversing the
188  * stack.  We distinguish the two by checking whether the pointer is
189  * into text-space or not.
190  */
191  
192 #define INFO_TBL_CONST  const
193
194 #endif /* INFOTABLES_H */