fix bug
[c11tester.git] / predicate.cc
1 #include "predicate.h"
2
3 Predicate::Predicate(FuncInst * func_inst, bool is_entry) :
4         func_inst(func_inst),
5         entry_predicate(is_entry),
6         pred_expressions(),
7         children(),
8         parents()
9 {}
10
11 unsigned int pred_expr_hash(struct pred_expr * expr)
12 {
13         return (unsigned int)((uintptr_t)expr);
14 }
15
16 bool pred_expr_equal(struct pred_expr * p1, struct pred_expr * p2)
17 {
18         if (p1->token != p2->token)
19                 return false;
20         if (p1->token == EQUALITY && p1->location != p2->location)
21                 return false;
22         if (p1->value != p2->value)
23                 return false;
24         return true;
25 }
26
27 void Predicate::add_predicate(token_t token, void * location, bool value)
28 {
29         struct pred_expr *ptr = new pred_expr(token, location, value);
30         pred_expressions.add(ptr);
31 }
32
33 void Predicate::add_child(Predicate * child)
34 {
35         /* check duplication? */
36         children.push_back(child);
37 }
38
39 void Predicate::add_parent(Predicate * parent)
40 {
41         /* check duplication? */
42         parents.push_back(parent);
43 }
44
45 void Predicate::print_predicate()
46 {
47         model_print("\"%p\" [shape=box, label=\"\n", this);
48         if (entry_predicate) {
49                 model_print("entry node\"];\n");
50                 return;
51         }
52
53         func_inst->print();
54
55         PredExprSetIter * it = pred_expressions.iterator();
56
57         if (pred_expressions.getSize() == 0)
58                 model_print("no predicate\n");
59
60         while (it->hasNext()) {
61                 struct pred_expr * expr = it->next();
62                 model_print("predicate: token: %d, location: %p, value: %d\n", expr->token, expr->location, expr->value);
63         }
64         model_print("\"];\n");
65 }
66
67 void Predicate::print_pred_subtree()
68 {
69         print_predicate();
70         for (uint i = 0; i < children.size(); i++) {
71                 Predicate * child = children[i];
72                 child->print_pred_subtree();
73                 model_print("\"%p\" -> \"%p\"\n", this, child);
74         }
75
76         if (backedge != NULL)
77                 model_print("\"%p\" -> \"%p\"[style=dashed, color=grey]\n", this, backedge);
78 }