3 * Copyright (C) 2002-2007, The Perl Foundation.
6 #ifndef PARROT_IMCC_SYMREG_H_GUARD
7 #define PARROT_IMCC_SYMREG_H_GUARD
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)
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
{
53 struct _Instruction
*first_ins
;
54 struct _Instruction
*last_ins
;
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
{
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 */
89 typedef struct _SymHash
{
97 typedef struct ident_t Identifier
;
103 typedef struct namespace_t Namespace
;
110 EXTERN Namespace
* _namespace
;
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
),
142 __attribute__nonnull__(1)
143 __attribute__nonnull__(2)
144 __attribute__nonnull__(3)
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)
154 void _store_symreg(ARGMOD(SymHash
*hsh
), ARGMOD(SymReg
*r
))
155 __attribute__nonnull__(1)
156 __attribute__nonnull__(2)
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)
171 void add_pcc_cc(ARGMOD(SymReg
*r
), ARGIN(SymReg
*arg
))
172 __attribute__nonnull__(1)
173 __attribute__nonnull__(2)
176 void add_pcc_multi(ARGMOD(SymReg
*r
), ARGIN_NULLOK(SymReg
*arg
))
177 __attribute__nonnull__(1)
180 void add_pcc_result(ARGMOD(SymReg
*r
), ARGMOD(SymReg
*arg
))
181 __attribute__nonnull__(1)
182 __attribute__nonnull__(2)
186 void add_pcc_sub(ARGMOD(SymReg
*r
), ARGIN(SymReg
*arg
))
187 __attribute__nonnull__(1)
188 __attribute__nonnull__(2)
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)
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);
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)
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);
228 unsigned int hash_str(ARGIN(const char *str
))
229 __attribute__nonnull__(1);
232 PARROT_CANNOT_RETURN_NULL
233 SymReg
* link_keys(PARROT_INTERP
,
235 ARGMOD(SymReg
**keys
),
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
),
254 __attribute__nonnull__(1)
255 __attribute__nonnull__(2)
256 __attribute__nonnull__(4)
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)
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 */
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 */
357 typedef struct pcc_sub_t
{
359 int *arg_flags
; /* :slurpy, :optional, ... */
364 int *ret_flags
; /* :slurpy, :optional, ... */
370 int flags
; /* isNCI, isTAIL_CALL */
383 #endif /* PARROT_IMCC_SYMREG_H_GUARD */
387 * c-file-style: "parrot"
389 * vim: expandtab shiftwidth=4: