new.
authorGötz Lindenmaier <goetz@ipd.info.uni-karlsruhe.de>
Thu, 30 Jan 2003 11:30:47 +0000 (11:30 +0000)
committerGötz Lindenmaier <goetz@ipd.info.uni-karlsruhe.de>
Thu, 30 Jan 2003 11:30:47 +0000 (11:30 +0000)
[r677]

ir/tr/trvrfy.c [new file with mode: 0644]
ir/tr/trvrfy.h [new file with mode: 0644]

diff --git a/ir/tr/trvrfy.c b/ir/tr/trvrfy.c
new file mode 100644 (file)
index 0000000..731977a
--- /dev/null
@@ -0,0 +1,70 @@
+
+#include "trvrfy.h"
+
+static int check_class(type *tp) {
+  int i, j, k;
+  int found;
+
+  //printf("\n"); DDMT(tp);
+
+  for (i = 0; i < get_class_n_members(tp); i++) {
+
+    entity *mem = get_class_member(tp, i);
+    assert(mem && "NULL members not allowed");
+    //printf(" %d, %d", get_entity_n_overwrites(mem), get_class_n_supertypes(tp)); DDME(mem);
+    if (!mem) return error_null_mem;
+    assert(get_entity_n_overwrites(mem) <= get_class_n_supertypes(tp));
+    for (j = 0; j < get_entity_n_overwrites(mem); j++) {
+      entity *ovw = get_entity_overwrites(mem, j);
+      //printf(" overwrites: "); DDME(ovw);
+      /* Check whether ovw is member of one of tp's supertypes. If so,
+        the representation is correct. */
+      found = false;
+      for (k = 0; k < get_class_n_supertypes(tp); k++) {
+       if (get_class_member_index(get_class_supertype(tp, k), ovw) >= 0) {
+         found = true;
+         break;
+       }
+      }
+      if (!found) {
+       DDMT(tp); DDME(mem);
+       assert(found && "overwrites an entity not contained in direct supertype");
+       return error_ent_not_cont;
+      }
+    }
+
+  }
+  return 0;
+}
+
+static int check_type(type *tp) {
+  switch (get_type_tpop_code(tp)) {
+  case tpo_class:
+    return check_class(tp);
+  default: break;
+  }
+  return 0;
+}
+
+
+static int check_entity(entity *ent) {
+  return 0;
+}
+
+static void check_tore(type_or_ent *tore, void *env) {
+  int *res = env;
+  if (is_type(tore)) {
+    *res = check_type((type *)tore);
+  } else {
+    assert(is_entity(tore));
+    *res = check_entity((entity *)tore);
+  }
+}
+
+
+int tr_vrfy() {
+  int res;
+
+  type_walk(check_tore, NULL, &res);
+  return res;
+}
diff --git a/ir/tr/trvrfy.h b/ir/tr/trvrfy.h
new file mode 100644 (file)
index 0000000..c52e007
--- /dev/null
@@ -0,0 +1,41 @@
+
+
+#ifndef TRVRFY_H
+#define TRVRFY_H
+
+/**
+ * @file trvrfy.h
+ *
+ * Methods to verify the type representations.
+ *
+ * @author Goetz Lindenmaier
+ *
+ * Methods to verify the type representations.
+ * Copyright 2003 University of Karlsruhe.
+ * Created 29.1.2003.
+ *
+ * $Id$
+ */
+
+#include "firm.h"
+
+/**
+ * possible error codes
+ */
+enum  trvrfy_error_codes {
+  no_error = 0,
+  error_ent_not_cont = 1,
+  error_null_mem,
+};
+
+
+/**
+ * Walks the type information and performs a set of sanity checks.
+ *
+ * @return
+ *    0 if graph is correct
+ *    else error code.
+ */
+int tr_vrfy();
+
+#endif /* TRVRFY_H */