3 #include "concretepredicate.h"
5 Predicate::Predicate(FuncInst * func_inst, bool is_entry) :
7 entry_predicate(is_entry),
16 Predicate::~Predicate()
18 // parent and func_inst should not be deleted
19 pred_expressions.reset();
24 unsigned int pred_expr_hash(struct pred_expr * expr)
26 return (unsigned int)((uintptr_t)expr);
29 bool pred_expr_equal(struct pred_expr * p1, struct pred_expr * p2)
31 if (p1->token != p2->token)
33 if (p1->token == EQUALITY && p1->func_inst != p2->func_inst)
35 if (p1->value != p2->value)
40 void Predicate::add_predicate_expr(token_t token, FuncInst * func_inst, bool value)
42 struct pred_expr *ptr = new pred_expr(token, func_inst, value);
43 pred_expressions.add(ptr);
46 void Predicate::add_child(Predicate * child)
48 /* check duplication? */
49 children.push_back(child);
52 void Predicate::copy_predicate_expr(Predicate * other)
54 PredExprSet * other_pred_expressions = other->get_pred_expressions();
55 PredExprSetIter * it = other_pred_expressions->iterator();
57 while (it->hasNext()) {
58 struct pred_expr * ptr = it->next();
59 struct pred_expr * copy = new pred_expr(ptr->token, ptr->func_inst, ptr->value);
60 pred_expressions.add(copy);
64 /* Evaluate predicate expressions against the given inst_act_map */
65 ConcretePredicate * Predicate::evaluate(inst_act_map_t * inst_act_map, thread_id_t tid)
67 ConcretePredicate * concrete = new ConcretePredicate(tid);
68 PredExprSetIter * it = pred_expressions.iterator();
70 while (it->hasNext()) {
71 struct pred_expr * ptr = it->next();
78 FuncInst * to_be_compared;
79 ModelAction * last_act;
81 to_be_compared = ptr->func_inst;
82 last_act = inst_act_map->get(to_be_compared);
83 value = last_act->get_reads_from_value();
91 concrete->add_expression(ptr->token, value, ptr->value);
97 void Predicate::print_predicate()
99 model_print("\"%p\" [shape=box, label=\"\n", this);
100 if (entry_predicate) {
101 model_print("entry node\"];\n");
107 PredExprSetIter * it = pred_expressions.iterator();
109 if (pred_expressions.getSize() == 0)
110 model_print("predicate unset\n");
112 while (it->hasNext()) {
113 struct pred_expr * expr = it->next();
114 FuncInst * inst = expr->func_inst;
115 switch (expr->token) {
119 model_print("predicate token: equality, position: %s, value: %d\n", inst->get_position(), expr->value);
122 model_print("predicate token: nullity, value: %d\n", expr->value);
125 model_print("unknown predicate token\n");
131 model_print("Does write\n");
133 model_print("Count: %d\n", exploration_count);
134 model_print("\"];\n");
137 void Predicate::print_pred_subtree()
140 for (uint i = 0; i < children.size(); i++) {
141 Predicate * child = children[i];
142 child->print_pred_subtree();
143 model_print("\"%p\" -> \"%p\"\n", this, child);
146 PredSetIter * it = backedges.iterator();
147 while (it->hasNext()) {
148 Predicate * backedge = it->next();
149 model_print("\"%p\" -> \"%p\"[style=dashed, color=grey]\n", this, backedge);