6a35fcc406f207e6c1daefe3a3992cdf34ab6e76
[c11tester.git] / predicate.h
1 #ifndef __PREDICATE_H__
2 #define __PREDICATE_H__
3
4 #include "hashset.h"
5 #include "predicatetypes.h"
6 #include "classlist.h"
7
8 unsigned int pred_expr_hash (struct pred_expr *);
9 bool pred_expr_equal(struct pred_expr *, struct pred_expr *);
10 typedef HashSet<struct pred_expr *, uintptr_t, 0, model_malloc, model_calloc, model_free, pred_expr_hash, pred_expr_equal> PredExprSet;
11 typedef HSIterator<struct pred_expr *, uintptr_t, 0, model_malloc, model_calloc, model_free, pred_expr_hash, pred_expr_equal> PredExprSetIter;
12
13 class Predicate {
14 public:
15         Predicate(FuncInst * func_inst, bool is_entry = false, bool is_exit = false);
16         ~Predicate();
17
18         FuncInst * get_func_inst() { return func_inst; }
19         PredExprSet * get_pred_expressions() { return &pred_expressions; }
20
21         void add_predicate_expr(token_t token, FuncInst * func_inst, bool value);
22         void add_child(Predicate * child);
23         void set_parent(Predicate * parent_pred) { parent = parent_pred; }
24         void set_exit(Predicate * exit_pred) { exit = exit_pred; }
25         void add_backedge(Predicate * back_pred) { backedges.add(back_pred); }
26         void copy_predicate_expr(Predicate * other);
27
28         ModelVector<Predicate *> * get_children() { return &children; }
29         Predicate * get_parent() { return parent; }
30         Predicate * get_exit() { return exit; }
31         PredSet * get_backedges() { return &backedges; }
32
33         bool is_entry_predicate() { return entry_predicate; }
34         void set_entry_predicate() { entry_predicate = true; }
35
36         /* Whether func_inst does write or not */
37         bool is_write() { return does_write; }
38         void set_write(bool is_write) { does_write = is_write; }
39
40         ConcretePredicate * evaluate(inst_act_map_t * inst_act_map, thread_id_t tid);
41
42         uint32_t get_expl_count() { return exploration_count; }
43         uint32_t get_fail_count() { return failure_count; }
44         void incr_expl_count() { exploration_count++; }
45         void incr_fail_count() { failure_count++; }
46
47         void print_predicate();
48         void print_pred_subtree();
49
50         MEMALLOC
51 private:
52         FuncInst * func_inst;
53         bool entry_predicate;
54         bool exit_predicate;
55         bool does_write;
56         uint32_t exploration_count;
57         uint32_t failure_count;
58
59         /* May have multiple predicate expressions */
60         PredExprSet pred_expressions;
61         ModelVector<Predicate *> children;
62
63         /* Only a single parent may exist */
64         Predicate * parent;
65         Predicate * exit;
66
67         /* May have multiple back edges, e.g. nested loops */
68         PredSet backedges;
69 };
70
71 #endif /* __PREDICATE_H__ */