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 assert(get_entity_n_overwrites(mem) <= get_class_n_supertypes(tp));
23 for (j = 0; j < get_entity_n_overwrites(mem); j++) {
24 entity *ovw = get_entity_overwrites(mem, j);
25 //printf(" overwrites: "); DDME(ovw);
26 /* Check whether ovw is member of one of tp's supertypes. If so,
27 the representation is correct. */
29 for (k = 0; k < get_class_n_supertypes(tp); k++) {
30 if (get_class_member_index(get_class_supertype(tp, k), ovw) >= 0) {
37 assert(found && "overwrites an entity not contained in direct supertype");
38 return error_ent_not_cont;
49 * Currently checks class types only.
51 static int check_type(type *tp) {
52 switch (get_type_tpop_code(tp)) {
54 return check_class(tp);
61 * helper environment struct for constant_on_wrong_obstack()
69 * called by the walker
71 static void on_irg_storage(ir_node *n, void *env) {
72 struct myenv * myenv = env;
74 myenv->res = node_is_in_irgs_storage(myenv->irg, n);
78 * checks wheater a given constant IR node is NOT on the
81 static int constant_on_wrong_irg(ir_node *n) {
84 env.res = 1; /* on right obstack */
85 env.irg = get_const_code_irg();
87 irg_walk(n, on_irg_storage, NULL, (void *)&env);
92 * Check if constants node are NOT on the constant IR graph.
94 static int constants_on_wrong_irg(entity *ent) {
95 if (get_entity_variability(ent) == uninitialized) return 0;
97 if (is_compound_entity(ent)) {
99 for (i = 0; i < get_compound_ent_n_values(ent); i++) {
100 if (constant_on_wrong_irg(get_compound_ent_value(ent, i)))
104 /* Might not be set if entity belongs to a description. */
105 if (get_atomic_ent_value(ent))
106 return constant_on_wrong_irg(get_atomic_ent_value(ent));
108 assert((is_class_type(get_entity_owner(ent)) &&
109 get_class_peculiarity(get_entity_owner(ent)) == description) &&
110 "Value in constant atomic entity not set.");
116 * Check an entity. Currently, we check only if initialized constants
117 * are build on the const irg graph.
120 * 0 if no error encountered
123 static int check_entity(entity *ent) {
124 if (constants_on_wrong_irg(ent)) {
125 assert(0 && "Contants placed on wrong IRG");
126 return error_const_on_wrong_irg;
132 * check types and entities
134 static void check_tore(type_or_ent *tore, void *env) {
137 *res = check_type((type *)tore);
139 assert(is_entity(tore));
140 *res = check_entity((entity *)tore);
145 * Verify types and entities.
150 type_walk(check_tore, NULL, &res);