fix bug - 'backedge' in predicate.cc uninitialized
[c11tester.git] / predicate.h
1 #ifndef __PREDICTAE_H__
2 #define __PREDICATE_H__
3
4 #include "funcinst.h"
5 #include "hashset.h"
6
7 unsigned int pred_expr_hash (struct pred_expr *);
8 bool pred_expr_equal(struct pred_expr *, struct pred_expr *);
9 typedef HashSet<struct pred_expr *, uintptr_t, 0, model_malloc, model_calloc, model_free, pred_expr_hash, pred_expr_equal> PredExprSet;
10 typedef HSIterator<struct pred_expr *, uintptr_t, 0, model_malloc, model_calloc, model_free, pred_expr_hash, pred_expr_equal> PredExprSetIter;
11
12 typedef enum predicate_token {
13         EQUALITY, NULLITY
14 } token_t;
15
16 /* If token is EQUALITY, then the predicate asserts whether
17  * this load should read the same value as the last value
18  * read at memory location specified in predicate_expr.
19  */
20 struct pred_expr {
21         pred_expr(token_t token, void * location, bool value) :
22                 token(token),
23                 location(location),
24                 value(value)
25         {}
26
27         token_t token;
28         void * location;
29         bool value;
30
31         MEMALLOC
32 };
33
34
35 class Predicate {
36 public:
37         Predicate(FuncInst * func_inst, bool is_entry = false);
38         ~Predicate();
39
40         FuncInst * get_func_inst() { return func_inst; }
41         PredExprSet * get_pred_expressions() { return &pred_expressions; }
42         void add_predicate(token_t token, void * location, bool value);
43         void add_child(Predicate * child);
44         void add_parent(Predicate * parent);
45         void set_backedge(Predicate * back_pred) { backedge = back_pred; }
46
47         ModelVector<Predicate *> * get_children() { return &children; }
48         ModelVector<Predicate *> * get_parents() { return &parents; }
49         Predicate * get_backedge() { return backedge; }
50
51         bool is_entry_predicate() { return entry_predicate; }
52         void set_entry_predicate() { entry_predicate = true; }
53
54         void print_predicate();
55         void print_pred_subtree();
56
57         MEMALLOC
58 private:
59         FuncInst * func_inst;
60         bool entry_predicate;
61
62         /* may have multiple predicates */
63         PredExprSet pred_expressions;
64         ModelVector<Predicate *> children;
65         ModelVector<Predicate *> parents;
66
67         /* assume almost one back edge exists */
68         Predicate * backedge;
69 };
70
71 #endif /* __PREDICATE_H__ */