3 #include "irgraph_t.h" /* for checking whether constant code is allocated
9 static int check_class(type *tp) {
13 /*printf("\n"); DDMT(tp);*/
15 for (i = 0; i < get_class_n_members(tp); i++) {
17 entity *mem = get_class_member(tp, i);
18 assert(mem && "NULL members not allowed");
19 /*printf(" %d, %d", get_entity_n_overwrites(mem), get_class_n_supertypes(tp)); DDME(mem);*/
20 if (!mem) return error_null_mem;
22 if (get_entity_n_overwrites(mem) > get_class_n_supertypes(tp)) {
24 assert(get_entity_n_overwrites(mem) <= get_class_n_supertypes(tp));
26 for (j = 0; j < get_entity_n_overwrites(mem); j++) {
27 entity *ovw = get_entity_overwrites(mem, j);
28 /*printf(" overwrites: "); DDME(ovw);*/
29 /* Check whether ovw is member of one of tp's supertypes. If so,
30 the representation is correct. */
32 for (k = 0; k < get_class_n_supertypes(tp); k++) {
33 if (get_class_member_index(get_class_supertype(tp, k), ovw) >= 0) {
40 assert(found && "overwrites an entity not contained in direct supertype");
41 return error_ent_not_cont;
52 * Currently checks class types only.
54 static int check_type(type *tp) {
55 switch (get_type_tpop_code(tp)) {
57 return check_class(tp);
64 * helper environment struct for constant_on_wrong_obstack()
72 * called by the walker
74 static void on_irg_storage(ir_node *n, void *env) {
75 struct myenv * myenv = env;
77 myenv->res = node_is_in_irgs_storage(myenv->irg, n);
79 /* We also test whether the setting of the visited flag is legal. */
80 assert(get_irn_visited(n) <= get_irg_visited(myenv->irg) &&
81 "Visited flag of node is larger than that of corresponding irg.");
85 * checks wheater a given constant IR node is NOT on the
88 static int constant_on_wrong_irg(ir_node *n) {
91 env.res = 1; /* on right obstack */
92 env.irg = get_const_code_irg();
94 irg_walk(n, on_irg_storage, NULL, (void *)&env);
99 * Check if constants node are NOT on the constant IR graph.
101 static int constants_on_wrong_irg(entity *ent) {
102 if (get_entity_variability(ent) == uninitialized) return 0;
104 if (is_compound_entity(ent)) {
106 for (i = 0; i < get_compound_ent_n_values(ent); i++) {
107 if (constant_on_wrong_irg(get_compound_ent_value(ent, i)))
111 /* Might not be set if entity belongs to a description. */
112 if (get_atomic_ent_value(ent))
113 return constant_on_wrong_irg(get_atomic_ent_value(ent));
115 assert((is_class_type(get_entity_owner(ent)) &&
116 get_class_peculiarity(get_entity_owner(ent)) == description) &&
117 "Value in constant atomic entity not set.");
123 * Check an entity. Currently, we check only if initialized constants
124 * are build on the const irg graph.
127 * 0 if no error encountered
130 static int check_entity(entity *ent) {
131 current_ir_graph = get_const_code_irg();
132 if (constants_on_wrong_irg(ent)) {
133 assert(0 && "Contants placed on wrong IRG");
134 return error_const_on_wrong_irg;
140 * check types and entities
142 static void check_tore(type_or_ent *tore, void *env) {
146 *res = check_type((type *)tore);
148 assert(is_entity(tore));
149 *res = check_entity((entity *)tore);
154 * Verify types and entities.
159 type_walk(check_tore, NULL, &res);