3 #include "concretepredicate.h"
5 Predicate::Predicate(FuncInst * func_inst, bool is_entry, bool is_exit) :
7 entry_predicate(is_entry),
8 exit_predicate(is_exit),
11 store_visible_count(0),
12 total_checking_count(0),
20 Predicate::~Predicate()
22 // parent and func_inst should not be deleted
23 pred_expressions.reset();
28 unsigned int pred_expr_hash(struct pred_expr * expr)
30 return (unsigned int)((uintptr_t)expr);
33 bool pred_expr_equal(struct pred_expr * p1, struct pred_expr * p2)
35 if (p1->token != p2->token)
37 if (p1->token == EQUALITY && p1->func_inst != p2->func_inst)
39 if (p1->value != p2->value)
44 void Predicate::add_predicate_expr(token_t token, FuncInst * func_inst, bool value)
46 struct pred_expr *ptr = new pred_expr(token, func_inst, value);
47 pred_expressions.add(ptr);
50 void Predicate::add_child(Predicate * child)
52 /* check duplication? */
53 children.push_back(child);
56 void Predicate::copy_predicate_expr(Predicate * other)
58 PredExprSet * other_pred_expressions = other->get_pred_expressions();
59 PredExprSetIter * it = other_pred_expressions->iterator();
61 while (it->hasNext()) {
62 struct pred_expr * ptr = it->next();
63 struct pred_expr * copy = new pred_expr(ptr->token, ptr->func_inst, ptr->value);
64 pred_expressions.add(copy);
68 /* Evaluate predicate expressions against the given inst_act_map */
69 ConcretePredicate * Predicate::evaluate(inst_act_map_t * inst_act_map, thread_id_t tid)
71 ConcretePredicate * concrete = new ConcretePredicate(tid);
72 PredExprSetIter * it = pred_expressions.iterator();
74 while (it->hasNext()) {
75 struct pred_expr * ptr = it->next();
82 FuncInst * to_be_compared;
83 ModelAction * last_act;
85 to_be_compared = ptr->func_inst;
86 last_act = inst_act_map->get(to_be_compared);
87 value = last_act->get_reads_from_value();
95 concrete->add_expression(ptr->token, value, ptr->value);
101 void Predicate::print_predicate()
103 model_print("\"%p\" [shape=box, label=\"\n", this);
104 if (entry_predicate) {
105 model_print("entry node\"];\n");
109 if (exit_predicate) {
110 model_print("exit node\"];\n");
116 if (pred_expressions.getSize() == 0)
117 model_print("predicate unset\n");
119 PredExprSetIter * it = pred_expressions.iterator();
120 while (it->hasNext()) {
121 struct pred_expr * expr = it->next();
122 FuncInst * inst = expr->func_inst;
123 switch (expr->token) {
127 model_print("predicate token: equality, position: %s, value: %d\n", inst->get_position(), expr->value);
130 model_print("predicate token: nullity, value: %d\n", expr->value);
133 model_print("unknown predicate token\n");
139 model_print("Does write\n");
142 double prob = (double) store_visible_count / total_checking_count;
143 model_print("Total checks: %d, visible count: %d; prob: %f\n", total_checking_count, store_visible_count, prob);
144 model_print("Exploration count: %d", exploration_count);
145 model_print("\"];\n");
148 void Predicate::print_pred_subtree()
151 for (uint i = 0; i < children.size(); i++) {
152 Predicate * child = children[i];
153 child->print_pred_subtree();
154 model_print("\"%p\" -> \"%p\"\n", this, child);
157 PredSetIter * it = backedges.iterator();
158 while (it->hasNext()) {
159 Predicate * backedge = it->next();
160 model_print("\"%p\" -> \"%p\"[style=dashed, color=grey]\n", this, backedge);
164 model_print("\"%p\" -> \"%p\"[style=dashed, color=red]\n", this, exit);