restructrue code of funcnode.cc, and planning for adding back edges in predicate...
[c11tester.git] / predicate.cc
1 #include "predicate.h"
2
3 Predicate::Predicate(FuncInst * func_inst) :
4         func_inst(func_inst),
5         entry_predicate(false),
6         pred_expressions(),
7         children()
8 {}
9
10 unsigned int pred_expr_hash(struct pred_expr * expr)
11 {
12         return (unsigned int)((uintptr_t)expr);
13 }
14
15 bool pred_expr_equal(struct pred_expr * p1, struct pred_expr * p2)
16 {
17         if (p1->token != p2->token)
18                 return false;
19         if (p1->token == EQUALITY && p1->location != p2->location)
20                 return false;
21         if (p1->value != p2->value)
22                 return false;
23         return true;
24 }
25
26 void Predicate::add_predicate(token_t token, void * location, bool value)
27 {
28         struct pred_expr *ptr = new pred_expr(token, location, value);
29         pred_expressions.add(ptr);
30 }
31
32 void Predicate::add_child(Predicate * child)
33 {
34         /* check duplication? */
35         children.push_back(child);
36 }
37
38 void Predicate::print_predicate()
39 {
40         model_print("\"%p\" [shape=box, label=\"\n", this);
41         func_inst->print();
42         PredExprSetIter * it = pred_expressions.iterator();
43
44         if (pred_expressions.getSize() == 0)
45                 model_print("no predicate\n");
46
47         while (it->hasNext()) {
48                 struct pred_expr * expr = it->next();
49                 model_print("predicate: token: %d, location: %p, value: %d\n", expr->token, expr->location, expr->value);
50         }
51         model_print("\"];\n");
52 }
53
54 void Predicate::print_pred_subtree()
55 {
56         print_predicate();
57         for (uint i = 0; i < children.size(); i++) {
58                 Predicate * child = children[i];
59                 child->print_pred_subtree();
60                 model_print("\"%p\" -> \"%p\"\n", this, child);
61         }
62 }