tagged release 0.6.4
[parrot.git] / compilers / imcc / symreg.h
blob065a8946db57da42c07e2b3ec855fcf14a149b61
1 /*
2 * $Id$
3 * Copyright (C) 2002-2007, The Perl Foundation.
4 */
6 #ifndef PARROT_IMCC_SYMREG_H_GUARD
7 #define PARROT_IMCC_SYMREG_H_GUARD
9 /* types */
11 #define VARTYPE_BIT(n) ((UINTVAL)1 << (n))
12 enum VARTYPE { /* variable type can be */
13 VTCONST = VARTYPE_BIT(0), /* constant */
14 VTREG = VARTYPE_BIT(1), /* register */
15 VTIDENTIFIER = VARTYPE_BIT(2), /* identifier */
16 VTADDRESS = VARTYPE_BIT(3), /* address */
17 VTREGKEY = VARTYPE_BIT(4), /* parrot [key;key..]), including registers */
18 VTPASM = VARTYPE_BIT(5), /* parrot register), colored from .emit */
19 VT_CONSTP = VARTYPE_BIT(6), /* pointer to constant value */
20 VT_PCC_SUB = VARTYPE_BIT(7), /* PCC subroutine call */
21 VT_FLAT = VARTYPE_BIT(8), /* var :flat */
22 VT_OPTIONAL = VARTYPE_BIT(9), /* var :optional */
23 /* include/parrot/packfile.h */
24 VT_START_SLICE = PF_VT_START_SLICE, /* x .. y slice range */
25 VT_END_SLICE = PF_VT_END_SLICE,
26 VT_START_ZERO = PF_VT_START_ZERO, /* .. y 0..start */
27 VT_END_INF = PF_VT_END_INF, /* x.. start..inf */
28 VT_SLICE_BITS = PF_VT_SLICE_BITS,
29 VT_ENCODED = VARTYPE_BIT(16), /* unicode string constant */
30 VT_OPT_FLAG = VARTYPE_BIT(17), /* var :opt_flag */
31 VT_NAMED = VARTYPE_BIT(18), /* var :named(name) */
32 VT_UNIQUE_REG = VARTYPE_BIT(19)
34 #undef VARTYPE_BIT
36 /* this VARTYPE needs register allocation and such */
37 #define VTREGISTER (VTREG | VTIDENTIFIER | VTREGKEY | VTPASM)
38 #define REG_NEEDS_ALLOC(r) ((r)->type & VTREGISTER)
40 enum LIFEFLAG { /* The status of a var inside a basic block can be */
41 LF_use = 1 << 0, /* block uses the the var before defining it */
42 LF_def = 1 << 1, /* block defines the variable */
43 LF_lv_in = 1 << 2, /* variable is alive at the begining of the block */
44 LF_lv_out = 1 << 3, /* variable is alive at the end of the block */
45 LF_lv_inside = 1 << 4, /* variable is alive at some moment in the block */
46 LF_lv_all = 1 << 5 /* variable is alive throughout the block */
49 /* Liveness represents the usage of a var inside a basic block
50 This is represented by pairs of [definition, usage] in *intervals: */
51 typedef struct _Life_range {
52 int flags;
53 struct _Instruction *first_ins;
54 struct _Instruction *last_ins;
55 } Life_range;
57 enum USAGE {
58 U_KEYED = 1 << 0, /* array, hash, keyed */
59 U_NEW = 1 << 1, /* PMC was inited */
60 U_GLOBAL = 1 << 3, /* symbol is global (fixup) */
61 U_LEXICAL = 1 << 4, /* symbol is lexical */
62 U_FIXUP = 1 << 5, /* maybe not global, force fixup */
63 U_NON_VOLATILE = 1 << 6 /* needs preserving */
66 typedef struct _SymReg {
67 char *name;
68 INTVAL type; /* Variable type */
69 INTVAL usage; /* s. USAGE above */
70 int set; /* parent register set/file */
71 int want_regno; /* wanted register number */
72 INTVAL color; /* Color: parrot register number
73 * and const table index of VTCONST */
74 int offset; /* used for label fixup */
75 int use_count; /* How often this symbol is used */
76 int lhs_use_count; /* Frequency of writing to this symbol*/
77 Life_range **life_info; /* Each block has a Life_range status */
78 struct _SymReg *next; /* used in the symbols hash */
79 struct _Instruction *first_ins; /* first and last instruction */
80 struct _Instruction *last_ins; /* this symbol is in */
81 /* also used by labels as position of label and last reference */
82 struct _SymReg *nextkey; /* keys */
83 struct _SymReg *reg; /* key->register for VTREGKEYs */
84 struct pcc_sub_t *pcc_sub; /* PCC subroutine */
85 struct _SymReg *used; /* used register in invoke */
86 int pmc_type; /* class enum */
87 } SymReg;
89 typedef struct _SymHash {
90 SymReg **data;
91 int size;
92 int entries;
93 } SymHash;
95 /* namespaces */
97 typedef struct ident_t Identifier;
98 struct ident_t {
99 char *name;
100 Identifier *next;
103 typedef struct namespace_t Namespace;
104 struct namespace_t {
105 Namespace *parent;
106 char *name;
107 Identifier *idents;
110 EXTERN Namespace * _namespace;
112 struct _IMC_Unit;
115 /* functions */
117 /* HEADERIZER BEGIN: compilers/imcc/symreg.c */
118 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
120 PARROT_CAN_RETURN_NULL
121 PARROT_WARN_UNUSED_RESULT
122 SymReg * _find_sym(PARROT_INTERP,
123 ARGIN_NULLOK(const Namespace *nspace),
124 ARGIN(const SymHash *hsh),
125 ARGIN(const char *name))
126 __attribute__nonnull__(1)
127 __attribute__nonnull__(3)
128 __attribute__nonnull__(4);
130 PARROT_CAN_RETURN_NULL
131 PARROT_WARN_UNUSED_RESULT
132 SymReg * _get_sym(ARGIN(const SymHash *hsh), ARGIN(const char *name))
133 __attribute__nonnull__(1)
134 __attribute__nonnull__(2);
136 PARROT_WARN_UNUSED_RESULT
137 PARROT_CANNOT_RETURN_NULL
138 SymReg * _mk_address(PARROT_INTERP,
139 ARGMOD(SymHash *hsh),
140 ARGIN(const char *name),
141 int uniq)
142 __attribute__nonnull__(1)
143 __attribute__nonnull__(2)
144 __attribute__nonnull__(3)
145 FUNC_MODIFIES(*hsh);
147 PARROT_WARN_UNUSED_RESULT
148 PARROT_CANNOT_RETURN_NULL
149 SymReg * _mk_const(ARGMOD(SymHash *hsh), ARGIN(const char *name), int t)
150 __attribute__nonnull__(1)
151 __attribute__nonnull__(2)
152 FUNC_MODIFIES(*hsh);
154 void _store_symreg(ARGMOD(SymHash *hsh), ARGMOD(SymReg *r))
155 __attribute__nonnull__(1)
156 __attribute__nonnull__(2)
157 FUNC_MODIFIES(*hsh)
158 FUNC_MODIFIES(*r);
160 void add_namespace(PARROT_INTERP, ARGMOD(struct _IMC_Unit *unit))
161 __attribute__nonnull__(1)
162 __attribute__nonnull__(2)
163 FUNC_MODIFIES(*unit);
165 void add_pcc_arg(ARGMOD(SymReg *r), ARGMOD(SymReg *arg))
166 __attribute__nonnull__(1)
167 __attribute__nonnull__(2)
168 FUNC_MODIFIES(*r)
169 FUNC_MODIFIES(*arg);
171 void add_pcc_cc(ARGMOD(SymReg *r), ARGIN(SymReg *arg))
172 __attribute__nonnull__(1)
173 __attribute__nonnull__(2)
174 FUNC_MODIFIES(*r);
176 void add_pcc_multi(ARGMOD(SymReg *r), ARGIN_NULLOK(SymReg *arg))
177 __attribute__nonnull__(1)
178 FUNC_MODIFIES(*r);
180 void add_pcc_result(ARGMOD(SymReg *r), ARGMOD(SymReg *arg))
181 __attribute__nonnull__(1)
182 __attribute__nonnull__(2)
183 FUNC_MODIFIES(*r)
184 FUNC_MODIFIES(*arg);
186 void add_pcc_sub(ARGMOD(SymReg *r), ARGIN(SymReg *arg))
187 __attribute__nonnull__(1)
188 __attribute__nonnull__(2)
189 FUNC_MODIFIES(*r);
191 void clear_globals(PARROT_INTERP)
192 __attribute__nonnull__(1);
194 void clear_locals(ARGIN_NULLOK(struct _IMC_Unit *unit));
195 void clear_sym_hash(ARGMOD(SymHash *hsh))
196 __attribute__nonnull__(1)
197 FUNC_MODIFIES(*hsh);
199 void create_symhash(ARGOUT(SymHash *hash))
200 __attribute__nonnull__(1)
201 FUNC_MODIFIES(*hash);
203 void debug_dump_sym_hash(ARGIN(const SymHash *hsh))
204 __attribute__nonnull__(1);
206 PARROT_MALLOC
207 PARROT_CANNOT_RETURN_NULL
208 SymReg * dup_sym(ARGIN(const SymReg *r))
209 __attribute__nonnull__(1);
211 PARROT_CAN_RETURN_NULL
212 PARROT_WARN_UNUSED_RESULT
213 SymReg * find_sym(PARROT_INTERP, ARGIN(const char *name))
214 __attribute__nonnull__(1)
215 __attribute__nonnull__(2);
217 void free_sym(ARGMOD(SymReg *r))
218 __attribute__nonnull__(1)
219 FUNC_MODIFIES(*r);
221 PARROT_CAN_RETURN_NULL
222 PARROT_WARN_UNUSED_RESULT
223 SymReg * get_sym(PARROT_INTERP, ARGIN(const char *name))
224 __attribute__nonnull__(1)
225 __attribute__nonnull__(2);
227 PARROT_PURE_FUNCTION
228 unsigned int hash_str(ARGIN(const char *str))
229 __attribute__nonnull__(1);
231 PARROT_MALLOC
232 PARROT_CANNOT_RETURN_NULL
233 SymReg * link_keys(PARROT_INTERP,
234 int nargs,
235 ARGMOD(SymReg **keys),
236 int force)
237 __attribute__nonnull__(1)
238 __attribute__nonnull__(3)
239 FUNC_MODIFIES(*keys);
241 PARROT_WARN_UNUSED_RESULT
242 PARROT_CANNOT_RETURN_NULL
243 SymReg * mk_const(PARROT_INTERP, ARGIN(const char *name), int t)
244 __attribute__nonnull__(1)
245 __attribute__nonnull__(2);
247 PARROT_CANNOT_RETURN_NULL
248 PARROT_IGNORABLE_RESULT
249 SymReg * mk_const_ident(PARROT_INTERP,
250 ARGIN(const char *name),
251 int t,
252 ARGMOD(SymReg *val),
253 int global)
254 __attribute__nonnull__(1)
255 __attribute__nonnull__(2)
256 __attribute__nonnull__(4)
257 FUNC_MODIFIES(*val);
259 PARROT_CANNOT_RETURN_NULL
260 PARROT_IGNORABLE_RESULT
261 SymReg * mk_ident(PARROT_INTERP, ARGIN(const char *name), int t)
262 __attribute__nonnull__(1)
263 __attribute__nonnull__(2);
265 PARROT_CANNOT_RETURN_NULL
266 PARROT_IGNORABLE_RESULT
267 SymReg* mk_ident_ur(PARROT_INTERP, ARGIN(const char *name), int t)
268 __attribute__nonnull__(1)
269 __attribute__nonnull__(2);
271 PARROT_WARN_UNUSED_RESULT
272 PARROT_CANNOT_RETURN_NULL
273 SymReg * mk_label_address(PARROT_INTERP, ARGIN(const char *name))
274 __attribute__nonnull__(1)
275 __attribute__nonnull__(2);
277 PARROT_WARN_UNUSED_RESULT
278 PARROT_CANNOT_RETURN_NULL
279 SymReg * mk_local_label(PARROT_INTERP, ARGIN(const char *name))
280 __attribute__nonnull__(1)
281 __attribute__nonnull__(2);
283 PARROT_WARN_UNUSED_RESULT
284 PARROT_CANNOT_RETURN_NULL
285 SymReg * mk_pasm_reg(PARROT_INTERP, ARGIN(const char *name))
286 __attribute__nonnull__(1)
287 __attribute__nonnull__(2);
289 PARROT_WARN_UNUSED_RESULT
290 PARROT_CANNOT_RETURN_NULL
291 SymReg * mk_pcc_sub(PARROT_INTERP, ARGIN(const char *name), int proto)
292 __attribute__nonnull__(1)
293 __attribute__nonnull__(2);
295 PARROT_WARN_UNUSED_RESULT
296 PARROT_CANNOT_RETURN_NULL
297 SymReg * mk_sub_address(PARROT_INTERP, ARGIN(const char *name))
298 __attribute__nonnull__(1)
299 __attribute__nonnull__(2);
301 PARROT_WARN_UNUSED_RESULT
302 PARROT_CANNOT_RETURN_NULL
303 SymReg * mk_sub_label(PARROT_INTERP, ARGIN(const char *name))
304 __attribute__nonnull__(1)
305 __attribute__nonnull__(2);
307 PARROT_WARN_UNUSED_RESULT
308 PARROT_CANNOT_RETURN_NULL
309 SymReg * mk_symreg(PARROT_INTERP, ARGIN(const char *name), int t)
310 __attribute__nonnull__(1)
311 __attribute__nonnull__(2);
313 PARROT_WARN_UNUSED_RESULT
314 PARROT_CANNOT_RETURN_NULL
315 SymReg * mk_temp_reg(PARROT_INTERP, int t)
316 __attribute__nonnull__(1);
318 void pop_namespace(PARROT_INTERP, ARGIN(const char *name))
319 __attribute__nonnull__(1)
320 __attribute__nonnull__(2);
322 void push_namespace(SHIM_INTERP, ARGIN(const char *name))
323 __attribute__nonnull__(2);
325 void store_symreg(PARROT_INTERP, ARGMOD(SymReg *r))
326 __attribute__nonnull__(1)
327 __attribute__nonnull__(2)
328 FUNC_MODIFIES(*r);
330 PARROT_MALLOC
331 PARROT_WARN_UNUSED_RESULT
332 PARROT_CANNOT_RETURN_NULL
333 char * symreg_to_str(ARGIN(const SymReg *s))
334 __attribute__nonnull__(1);
336 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
337 /* HEADERIZER END: compilers/imcc/symreg.c */
339 typedef enum {
340 P_NONE = 0x00, /* 0<<0 */
341 P_NEED_LEX = 0x01, /* 1<<0 */
342 /* P_XXXX = 0x02, */ /* 1<<1 */
343 P_METHOD = 0x04, /* 1<<2 */
344 P_ANON = SUB_FLAG_PF_ANON, /* 1<<3 0x8 - private3 */
345 P_MAIN = SUB_FLAG_PF_MAIN, /* 1<<4 0x10 - private4 */
346 P_LOAD = SUB_FLAG_PF_LOAD, /* 1<<5 0x20 - private5 */
347 P_IMMEDIATE = SUB_FLAG_PF_IMMEDIATE, /* 1<<6 0x40 - private6 */
348 P_POSTCOMP = SUB_FLAG_PF_POSTCOMP, /* 1<<7 0x80 - private7 */
349 P_INIT = SUB_COMP_FLAG_PF_INIT /* 1<<10 0x400 - 10 */
350 } pragma_enum_t;
352 typedef enum {
353 isNCI = 0x01,
354 isTAIL_CALL = 0x02
355 } pcc_flags_t;
357 typedef struct pcc_sub_t {
358 SymReg ** args;
359 int *arg_flags; /* :slurpy, :optional, ... */
360 int nargs;
361 SymReg *sub;
362 SymReg *cc;
363 SymReg ** ret;
364 int *ret_flags; /* :slurpy, :optional, ... */
365 int nret;
366 SymReg ** multi;
367 int nmulti;
368 INTVAL pragma;
369 int calls_a_sub;
370 int flags; /* isNCI, isTAIL_CALL */
371 int label;
372 SymReg * object;
373 } pcc_sub_t;
376 enum uniq_t {
377 U_add_once,
378 U_add_uniq_label,
379 U_add_uniq_sub,
380 U_add_all
383 #endif /* PARROT_IMCC_SYMREG_H_GUARD */
386 * Local variables:
387 * c-file-style: "parrot"
388 * End:
389 * vim: expandtab shiftwidth=4: