Fixes
[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         uint32_t get_scleep_score() { return sleep_score; }
45         void incr_expl_count();
46         void incr_fail_count();
47         void incr_sleep_score(uint32_t amount);
48         void decr_sleep_score(uint32_t amount);
49
50         void print_predicate();
51         void print_pred_subtree();
52
53         MEMALLOC
54 private:
55         FuncInst * func_inst;
56         bool entry_predicate;
57         bool exit_predicate;
58         bool does_write;
59
60         uint32_t exploration_count;
61         uint32_t failure_count;
62         uint32_t sleep_score;   /* 0 <= sleep_score <= 100 */
63
64         /* May have multiple predicate expressions */
65         PredExprSet pred_expressions;
66         ModelVector<Predicate *> children;
67
68         /* Only a single parent may exist */
69         Predicate * parent;
70         Predicate * exit;
71
72         /* May have multiple back edges, e.g. nested loops */
73         PredSet backedges;
74 };
75
76 #endif /* __PREDICATE_H__ */