3 * File name: ir/tr/trvrfy.c
4 * Purpose: Check types and entities for correctness.
5 * Author: Michael Beck, Goetz Lindenmaier
9 * Copyright: (c) 2003 Universität Karlsruhe
10 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
17 #include "irgraph_t.h" /* for checking whether constant code is allocated
23 static int check_class(type *tp) {
27 /*printf("\n"); DDMT(tp);*/
29 for (i = 0; i < get_class_n_members(tp); i++) {
31 entity *mem = get_class_member(tp, i);
32 assert(mem && "NULL members not allowed");
33 /*printf(" %d, %d", get_entity_n_overwrites(mem), get_class_n_supertypes(tp)); DDME(mem);*/
34 if (!mem) return error_null_mem;
36 if (get_entity_n_overwrites(mem) > get_class_n_supertypes(tp)) {
38 assert(get_entity_n_overwrites(mem) <= get_class_n_supertypes(tp));
40 for (j = 0; j < get_entity_n_overwrites(mem); j++) {
41 entity *ovw = get_entity_overwrites(mem, j);
42 /*printf(" overwrites: "); DDME(ovw);*/
43 /* Check whether ovw is member of one of tp's supertypes. If so,
44 the representation is correct. */
46 for (k = 0; k < get_class_n_supertypes(tp); k++) {
47 if (get_class_member_index(get_class_supertype(tp, k), ovw) >= 0) {
54 assert(found && "overwrites an entity not contained in direct supertype");
55 return error_ent_not_cont;
66 * Currently checks class types only.
68 static int check_type(type *tp) {
69 switch (get_type_tpop_code(tp)) {
71 return check_class(tp);
78 * helper environment struct for constant_on_wrong_obstack()
86 * called by the walker
88 static void on_irg_storage(ir_node *n, void *env) {
89 struct myenv * myenv = env;
91 myenv->res = node_is_in_irgs_storage(myenv->irg, n);
93 /* We also test whether the setting of the visited flag is legal. */
94 assert(get_irn_visited(n) <= get_irg_visited(myenv->irg) &&
95 "Visited flag of node is larger than that of corresponding irg.");
99 * checks wheater a given constant IR node is NOT on the
102 static int constant_on_wrong_irg(ir_node *n) {
105 env.res = 1; /* on right obstack */
106 env.irg = get_const_code_irg();
108 irg_walk(n, on_irg_storage, NULL, (void *)&env);
113 * Check if constants node are NOT on the constant IR graph.
115 static int constants_on_wrong_irg(entity *ent) {
116 if (get_entity_variability(ent) == variability_uninitialized) return 0;
118 if (is_compound_entity(ent)) {
120 for (i = 0; i < get_compound_ent_n_values(ent); i++) {
121 if (constant_on_wrong_irg(get_compound_ent_value(ent, i)))
125 /* Might not be set if entity belongs to a description. */
126 if (get_atomic_ent_value(ent))
127 return constant_on_wrong_irg(get_atomic_ent_value(ent));
129 assert((is_class_type(get_entity_owner(ent)) &&
130 get_class_peculiarity(get_entity_owner(ent)) == peculiarity_description) &&
131 "Value in constant atomic entity not set.");
137 * Check an entity. Currently, we check only if initialized constants
138 * are build on the const irg graph.
141 * 0 if no error encountered
144 static int check_entity(entity *ent) {
145 current_ir_graph = get_const_code_irg();
146 if (constants_on_wrong_irg(ent)) {
147 assert(0 && "Contants placed on wrong IRG");
148 return error_const_on_wrong_irg;
151 if ((get_entity_peculiarity(ent) == peculiarity_existent) &&
152 (get_entity_visibility(ent) != visibility_external_allocated) &&
153 (is_method_type(get_entity_type(ent))) &&
154 (!get_entity_irg(ent) || !(is_ir_graph(get_entity_irg(ent))))) {
155 assert(0 && "Method ents with pec_exist must have an irg");
156 return error_existent_entity_without_irg;
163 * check types and entities
165 static void check_tore(type_or_ent *tore, void *env) {
169 *res = check_type((type *)tore);
171 assert(is_entity(tore));
172 *res = check_entity((entity *)tore);
177 * Verify types and entities.
182 type_walk(check_tore, NULL, &res);