3 Predicate::Predicate(FuncInst * func_inst, bool is_entry) :
5 entry_predicate(is_entry),
12 unsigned int pred_expr_hash(struct pred_expr * expr)
14 return (unsigned int)((uintptr_t)expr);
17 bool pred_expr_equal(struct pred_expr * p1, struct pred_expr * p2)
19 if (p1->token != p2->token)
21 if (p1->token == EQUALITY && p1->func_inst != p2->func_inst)
23 if (p1->value != p2->value)
28 void Predicate::add_predicate_expr(token_t token, FuncInst * func_inst, bool value)
30 struct pred_expr *ptr = new pred_expr(token, func_inst, value);
31 pred_expressions.add(ptr);
34 void Predicate::add_child(Predicate * child)
36 /* check duplication? */
37 children.push_back(child);
40 void Predicate::copy_predicate_expr(Predicate * other)
42 PredExprSet * other_pred_expressions = other->get_pred_expressions();
43 PredExprSetIter * it = other_pred_expressions->iterator();
45 while (it->hasNext()) {
46 struct pred_expr * ptr = it->next();
47 struct pred_expr * copy = new pred_expr(ptr->token, ptr->func_inst, ptr->value);
48 pred_expressions.add(copy);
52 void Predicate::print_predicate()
54 model_print("\"%p\" [shape=box, label=\"\n", this);
55 if (entry_predicate) {
56 model_print("entry node\"];\n");
62 PredExprSetIter * it = pred_expressions.iterator();
64 if (pred_expressions.getSize() == 0)
65 model_print("no predicate\n");
67 while (it->hasNext()) {
68 struct pred_expr * expr = it->next();
69 FuncInst * inst = expr->func_inst;
70 switch (expr->token) {
72 model_print("predicate token: equality, position: %s, value: %d\n", inst->get_position(), expr->value);
75 model_print("predicate token: nullity, value: %d\n", expr->value);
78 model_print("unknown predicate token\n");
82 model_print("\"];\n");
85 void Predicate::print_pred_subtree()
88 for (uint i = 0; i < children.size(); i++) {
89 Predicate * child = children[i];
90 child->print_pred_subtree();
91 model_print("\"%p\" -> \"%p\"\n", this, child);
95 model_print("\"%p\" -> \"%p\"[style=dashed, color=grey]\n", this, backedge);