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
22 #include "type_or_entity.h"
24 /* Make types visible to allow most efficient access */
25 # include "entity_t.h"
28 typedef struct type_walk_env {
35 void type_walk_2(type_or_ent *tore,
36 void (pre)(type_or_ent*, void*),
37 void (post)(type_or_ent*, void*),
43 switch (get_kind(tore)) {
45 if (((entity *)tore)->visit >= type_visited) return; break;
47 if (((type *)tore)->visit >= type_visited) return; break;
52 /* execute pre method */
57 switch (get_kind(tore)) {
61 entity *ent = (entity *)tore;
62 ent->visit = type_visited;
63 type_walk_2((type_or_ent *)get_entity_owner(ent), pre, post, env);
64 type_walk_2((type_or_ent *)get_entity_type(ent), pre, post, env);
69 type *tp = (type *)tore;
70 mark_type_visited(tp);
71 switch (get_type_tpop_code(tp))
74 for (i=0; i<get_class_n_member(tp); i++)
75 type_walk_2((type_or_ent *)get_class_member(tp, i), pre, post, env);
76 for (i=0; i<get_class_n_subtype(tp); i++)
77 type_walk_2((type_or_ent *)get_class_subtype(tp, i), pre, post, env);
78 for (i=0; i<get_class_n_supertype(tp); i++) {
79 type_walk_2((type_or_ent *)get_class_supertype(tp, i), pre, post, env);
84 for (i=0; i<get_struct_n_member(tp); i++)
85 type_walk_2((type_or_ent *)get_struct_member(tp, i), pre, post, env);
90 for (i = 0; i < get_method_n_params(tp); i++)
91 type_walk_2((type_or_ent *)get_method_param_type(tp, i), pre, post, env);
92 for (i = 0; i < get_method_n_res(tp); i++)
93 type_walk_2((type_or_ent *)get_method_res_type(tp, i), pre, post, env);
98 for (i = 0; i < get_union_n_types(tp); i++)
99 type_walk_2((type_or_ent *)get_union_unioned_type(tp, i), pre, post, env);
103 type_walk_2((type_or_ent *)get_array_element_type(tp),
106 case tpo_enumeration:
110 type_walk_2((type_or_ent *)get_pointer_points_to_type(tp),
117 printf(" *** Faulty type! \n");
120 } break; /* end case k_type */
122 printf(" *** Faulty type or entity! \n");
126 /* execute post method */
133 void start_type_walk(ir_node *node, void *env) {
134 void *pre = ((type_walk_env *)env)->pre;
135 void *post = ((type_walk_env *)env)->post;
136 void *envi = ((type_walk_env *)env)->env;
140 switch (get_irn_opcode(node)) { /* node label */
142 if ( (get_SymConst_kind(node) == type_tag)
143 || (get_SymConst_kind(node) == size))
144 type_walk_2((type_or_ent *)get_SymConst_type(node), pre, post, envi);
147 type_walk_2((type_or_ent *)get_Sel_entity(node), pre, post, envi);
150 type_walk_2((type_or_ent *)get_Call_type(node), pre, post, envi);
153 type_walk_2((type_or_ent *)get_Alloc_type(node), pre, post, envi);
156 printf("here in typewalk\n");
157 type_walk_2((type_or_ent *)get_Free_type(node), pre, post, envi);
164 void type_walk(void (pre)(type_or_ent*, void*),
165 void (post)(type_or_ent*, void*),
169 type_walk_2((type_or_ent *)get_glob_type(), pre, post, env);
170 for (i = 0; i < get_irp_n_types(); i++) {
171 type_walk_2((type_or_ent *)get_irp_type(i), pre, post, env);
175 void type_walk_irg (ir_graph *irg,
176 void (pre)(type_or_ent*, void*),
177 void (post)(type_or_ent*, void*),
180 /* this is needed to pass the parameters to the walker that actually
181 walks the type information */
182 type_walk_env* type_env;
183 type_env = (type_walk_env *) malloc (sizeof(type_walk_env));
185 type_env->post = post;
189 irg_walk(get_irg_end(irg), start_type_walk, NULL, type_env);
191 type_walk_2((type_or_ent *)get_irg_ent(irg), pre, post, env);