3 #include "concretepredicate.h"
5 Predicate::Predicate(FuncInst * func_inst, bool is_entry) :
7 entry_predicate(is_entry),
15 Predicate::~Predicate()
17 // parent and func_inst should not be deleted
18 pred_expressions.reset();
23 unsigned int pred_expr_hash(struct pred_expr * expr)
25 return (unsigned int)((uintptr_t)expr);
28 bool pred_expr_equal(struct pred_expr * p1, struct pred_expr * p2)
30 if (p1->token != p2->token)
32 if (p1->token == EQUALITY && p1->func_inst != p2->func_inst)
34 if (p1->value != p2->value)
39 void Predicate::add_predicate_expr(token_t token, FuncInst * func_inst, bool value)
41 struct pred_expr *ptr = new pred_expr(token, func_inst, value);
42 pred_expressions.add(ptr);
45 void Predicate::add_child(Predicate * child)
47 /* check duplication? */
48 children.push_back(child);
51 void Predicate::copy_predicate_expr(Predicate * other)
53 PredExprSet * other_pred_expressions = other->get_pred_expressions();
54 PredExprSetIter * it = other_pred_expressions->iterator();
56 while (it->hasNext()) {
57 struct pred_expr * ptr = it->next();
58 struct pred_expr * copy = new pred_expr(ptr->token, ptr->func_inst, ptr->value);
59 pred_expressions.add(copy);
63 /* Evaluate predicate expressions against the given inst_act_map */
64 ConcretePredicate * Predicate::evaluate(inst_act_map_t * inst_act_map, thread_id_t tid)
66 ConcretePredicate * concrete = new ConcretePredicate(tid);
67 PredExprSetIter * it = pred_expressions.iterator();
69 while (it->hasNext()) {
70 struct pred_expr * ptr = it->next();
77 FuncInst * to_be_compared;
78 ModelAction * last_act;
80 to_be_compared = ptr->func_inst;
81 last_act = inst_act_map->get(to_be_compared);
82 value = last_act->get_reads_from_value();
90 concrete->add_expression(ptr->token, value, ptr->value);
96 void Predicate::print_predicate()
98 model_print("\"%p\" [shape=box, label=\"\n", this);
99 if (entry_predicate) {
100 model_print("entry node\"];\n");
106 PredExprSetIter * it = pred_expressions.iterator();
108 if (pred_expressions.getSize() == 0)
109 model_print("predicate unset\n");
111 while (it->hasNext()) {
112 struct pred_expr * expr = it->next();
113 FuncInst * inst = expr->func_inst;
114 switch (expr->token) {
118 model_print("predicate token: equality, position: %s, value: %d\n", inst->get_position(), expr->value);
121 model_print("predicate token: nullity, value: %d\n", expr->value);
124 model_print("unknown predicate token\n");
130 model_print("Does write\n");
132 model_print("\"];\n");
135 void Predicate::print_pred_subtree()
138 for (uint i = 0; i < children.size(); i++) {
139 Predicate * child = children[i];
140 child->print_pred_subtree();
141 model_print("\"%p\" -> \"%p\"\n", this, child);
144 PredSetIter * it = backedges.iterator();
145 while (it->hasNext()) {
146 Predicate * backedge = it->next();
147 model_print("\"%p\" -> \"%p\"[style=dashed, color=grey]\n", this, backedge);