1 /* Copyright (C) 1998 - 2000 by Universitaet Karlsruhe
2 ** All rights reserved.
4 ** Author: Goetz Lindenmaier
6 ** traverse the type information. The walker walks the whole ir graph
7 ** to find the distinct type trees in the type graph forest.
8 ** - execute the pre function before recursion
9 ** - execute the post function after recursion
21 #include "irgraph_t.h"
24 #include "type_or_entity.h"
27 /* Make types visible to allow most efficient access */
31 typedef struct type_walk_env {
38 void type_walk_2(type_or_ent *tore,
39 void (pre)(type_or_ent*, void*),
40 void (post)(type_or_ent*, void*),
46 switch (get_kind(tore)) {
48 if (((entity *)tore)->visit >= type_visited) return;
51 if(type_id == get_type_tpop((type*)tore)) {
52 type_walk_2((type_or_ent *)skip_tid((type *)tore), pre, post, env);
55 if (((type *)tore)->visit >= type_visited) return;
61 /* execute pre method */
66 switch (get_kind(tore)) {
70 entity *ent = (entity *)tore;
71 ent->visit = type_visited;
72 type_walk_2((type_or_ent *)get_entity_owner(ent), pre, post, env);
73 type_walk_2((type_or_ent *)get_entity_type(ent), pre, post, env);
78 type *tp = (type *)tore;
79 mark_type_visited(tp);
80 switch (get_type_tpop_code(tp)) {
83 for (i=0; i<get_class_n_supertype(tp); i++)
84 type_walk_2((type_or_ent *)get_class_supertype(tp, i), pre, post, env);
85 for (i=0; i<get_class_n_member(tp); i++)
86 type_walk_2((type_or_ent *)get_class_member(tp, i), pre, post, env);
87 for (i=0; i<get_class_n_subtype(tp); i++)
88 type_walk_2((type_or_ent *)get_class_subtype(tp, i), pre, post, env);
93 for (i=0; i<get_struct_n_member(tp); i++)
94 type_walk_2((type_or_ent *)get_struct_member(tp, i), pre, post, env);
99 for (i = 0; i < get_method_n_params(tp); i++)
100 type_walk_2((type_or_ent *)get_method_param_type(tp, i), pre, post, env);
101 for (i = 0; i < get_method_n_res(tp); i++)
102 type_walk_2((type_or_ent *)get_method_res_type(tp, i), pre, post, env);
107 for (i = 0; i < get_union_n_members(tp); i++)
108 type_walk_2((type_or_ent *)get_union_member(tp, i), pre, post, env);
112 type_walk_2((type_or_ent *)get_array_element_type(tp),
114 type_walk_2((type_or_ent *)get_array_element_entity(tp),
117 case tpo_enumeration:
121 type_walk_2((type_or_ent *)get_pointer_points_to_type(tp),
129 printf(" *** Faulty type! \n");
132 } break; /* end case k_type */
134 printf(" *** Faulty type or entity! \n");
138 /* execute post method */
145 void start_type_walk(ir_node *node, void *env) {
146 void *pre = ((type_walk_env *)env)->pre;
147 void *post = ((type_walk_env *)env)->post;
148 void *envi = ((type_walk_env *)env)->env;
152 switch (get_irn_opcode(node)) { /* node label */
154 if ( (get_SymConst_kind(node) == type_tag)
155 || (get_SymConst_kind(node) == size))
156 type_walk_2((type_or_ent *)get_SymConst_type(node), pre, post, envi);
159 type_walk_2((type_or_ent *)get_Sel_entity(node), pre, post, envi);
162 type_walk_2((type_or_ent *)get_Call_type(node), pre, post, envi);
165 type_walk_2((type_or_ent *)get_Alloc_type(node), pre, post, envi);
168 type_walk_2((type_or_ent *)get_Free_type(node), pre, post, envi);
175 void type_walk(void (pre)(type_or_ent*, void*),
176 void (post)(type_or_ent*, void*),
180 /*type_walk_2((type_or_ent *)get_glob_type(), pre, post, env);
181 global type is on the list visited below, too. */
182 for (i = 0; i < get_irp_n_types(); i++) {
183 type_walk_2((type_or_ent *)get_irp_type(i), pre, post, env);
187 void type_walk_irg (ir_graph *irg,
188 void (pre)(type_or_ent*, void*),
189 void (post)(type_or_ent*, void*),
192 /* this is needed to pass the parameters to the walker that actually
193 walks the type information */
194 type_walk_env* type_env;
195 type_env = (type_walk_env *) malloc (sizeof(type_walk_env));
197 type_env->post = post;
201 irg_walk(get_irg_end(irg), start_type_walk, NULL, type_env);
203 type_walk_2((type_or_ent *)get_irg_ent(irg), pre, post, env);
209 void type_walk_s2s_2(type_or_ent *tore,
210 void (pre)(type_or_ent*, void*),
211 void (post)(type_or_ent*, void*),
217 switch (get_kind(tore)) {
219 if (((entity *)tore)->visit >= type_visited) return;
222 if(type_id == get_type_tpop((type*)tore)) {
223 type_walk_s2s_2((type_or_ent *)skip_tid((type *)tore), pre, post, env);
226 if (((type *)tore)->visit >= type_visited) return;
233 switch (get_kind(tore)) {
236 type *tp = (type *)tore;
237 mark_type_visited(tp);
238 switch (get_type_tpop_code(tp)) {
241 for (i = 0; i < get_class_n_supertype(tp); i++) {
242 type_walk_s2s_2((type_or_ent *)get_class_supertype(tp, i), pre,
245 /* execute pre method */
248 tp = skip_tid((type*)tore);
250 for (i = 0; i < get_class_n_subtype(tp); i++) {
251 type_walk_s2s_2((type_or_ent *)get_class_subtype(tp, i), pre,
255 /* execute post method */
264 case tpo_enumeration:
271 printf(" *** Faulty type! \n");
274 } break; /* end case k_type */
279 printf(" *** Faulty type or entity! \n");
285 void type_walk_super2sub(void (pre)(type_or_ent*, void*),
286 void (post)(type_or_ent*, void*),
291 type_walk_s2s_2((type_or_ent *)get_glob_type(), pre, post, env);
292 for (i = 0; i < get_irp_n_types(); i++) {
293 tp = get_irp_type(i);
294 type_walk_s2s_2((type_or_ent *)tp, pre, post, env);
298 /*****************************************************************************/
301 void type_walk_super_2(type_or_ent *tore,
302 void (pre)(type_or_ent*, void*),
303 void (post)(type_or_ent*, void*),
309 switch (get_kind(tore)) {
311 if (((entity *)tore)->visit >= type_visited) return;
314 if(type_id == get_type_tpop((type*)tore)) {
315 type_walk_super_2((type_or_ent *)skip_tid((type *)tore), pre, post, env);
318 if (((type *)tore)->visit >= type_visited) return;
325 switch (get_kind(tore)) {
328 type *tp = (type *)tore;
329 mark_type_visited(tp);
330 switch (get_type_tpop_code(tp)) {
333 /* execute pre method */
336 tp = skip_tid((type*)tore);
338 for (i = 0; i < get_class_n_supertype(tp); i++) {
339 type_walk_super_2((type_or_ent *)get_class_supertype(tp, i), pre,
343 /* execute post method */
352 case tpo_enumeration:
359 printf(" *** Faulty type! \n");
362 } break; /* end case k_type */
367 printf(" *** Faulty type or entity! \n");
373 void type_walk_super(void (pre)(type_or_ent*, void*),
374 void (post)(type_or_ent*, void*),
379 type_walk_super_2((type_or_ent *)get_glob_type(), pre, post, env);
380 for (i = 0; i < get_irp_n_types(); i++) {
381 tp = get_irp_type(i);
382 type_walk_super_2((type_or_ent *)tp, pre, post, env);
386 /*****************************************************************************/
389 void class_walk_s2s_2(type *tp,
390 void (pre)(type*, void*),
391 void (post)(type*, void*),
397 if (tp->visit >= type_visited) return;
399 assert(is_class_type(tp));
400 /* Assure all supertypes are visited before */
401 for (i=0; i < get_class_n_supertype(tp); i++) {
402 if (get_type_visited(get_class_supertype(tp, i)) < type_visited)
406 mark_type_visited(tp);
408 /* execute pre method */
412 tp = skip_tid((type*)tp);
413 for (i=0; i<get_class_n_subtype(tp); i++) {
414 class_walk_s2s_2(get_class_subtype(tp, i), pre, post, env);
416 /* execute post method */
424 void class_walk_super2sub(void (pre)(type*, void*),
425 void (post)(type*, void*),
431 for (i = 0; i < get_irp_n_types(); i++) {
432 tp = get_irp_type(i);
433 if (is_class_type(tp) &&
434 (get_class_n_supertype(tp) == 0) &&
435 (tp->visit < type_visited) &&
436 (!is_frame_type(tp)) &&
437 (tp != get_glob_type())) {
438 class_walk_s2s_2(tp, pre, post, env);