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