Run tabbing pass
[c11tester.git] / history.h
1 #ifndef __HISTORY_H__
2 #define __HISTORY_H__
3
4 #include "common.h"
5 #include "classlist.h"
6 #include "hashtable.h"
7 #include "threads-model.h"
8
9 class ModelHistory {
10 public:
11         ModelHistory();
12         ~ModelHistory();
13
14         void enter_function(const uint32_t func_id, thread_id_t tid);
15         void exit_function(const uint32_t func_id, thread_id_t tid);
16
17         uint32_t get_func_counter() { return func_counter; }
18         void incr_func_counter() { func_counter++; }
19
20         void resize_func_nodes(uint32_t max_func_id);
21         void process_action(ModelAction *act, thread_id_t tid);
22
23         HashTable<const char *, uint32_t, uintptr_t, 4, model_malloc, model_calloc, model_free> * getFuncMap() { return &func_map; }
24         ModelVector<const char *> * getFuncMapRev() { return &func_map_rev; }
25
26         ModelVector<FuncNode *> * getFuncNodes() { return &func_nodes; }
27         FuncNode * get_func_node(uint32_t func_id);
28         FuncNode * get_curr_func_node(thread_id_t tid);
29
30         void update_write_history(void * location, uint64_t write_val);
31         HashTable<void *, value_set_t *, uintptr_t, 0> * getWriteHistory() { return write_history; }
32         void update_loc_rd_func_nodes_map(void * location, FuncNode * node);
33         void update_loc_wr_func_nodes_map(void * location, FuncNode * node);
34         SnapVector<FuncNode *> * getRdFuncNodes(void * location);
35         SnapVector<FuncNode *> * getWrFuncNodes(void * location);
36
37         void add_waiting_write(ConcretePredicate * concrete);
38         void remove_waiting_write(thread_id_t tid);
39         void check_waiting_write(ModelAction * write_act);
40         SnapVector<ConcretePredicate *> * getThrdWaitingWrite() { return thrd_waiting_write; }
41
42         WaitObj * getWaitObj(thread_id_t tid);
43         void add_waiting_thread(thread_id_t self_id, thread_id_t waiting_for_id, FuncNode * target_node, int dist);
44         void remove_waiting_thread(thread_id_t tid);
45         void stop_waiting_for_node(thread_id_t self_id, thread_id_t waiting_for_id, FuncNode * target_node);
46
47         SnapVector<inst_act_map_t *> * getThrdInstActMap(uint32_t func_id);
48
49         void set_new_exec_flag();
50         void dump_func_node_graph();
51         void print_func_node();
52         void print_waiting_threads();
53
54         MEMALLOC
55 private:
56         uint32_t func_counter;
57
58         /* Map function names to integer ids */
59         HashTable<const char *, uint32_t, uintptr_t, 4, model_malloc, model_calloc, model_free> func_map;
60
61         /* Map integer ids to function names */
62         ModelVector<const char *> func_map_rev;
63
64         ModelVector<FuncNode *> func_nodes;
65
66         /* Map a location to a set of values that have been written to it */
67         HashTable<void *, value_set_t *, uintptr_t, 0> * write_history;
68
69         /* Map a location to FuncNodes that may read from it */
70         HashTable<void *, SnapVector<FuncNode *> *, uintptr_t, 0> * loc_rd_func_nodes_map;
71
72         /* Map a location to FuncNodes that may write to it */
73         HashTable<void *, SnapVector<FuncNode *> *, uintptr_t, 0> * loc_wr_func_nodes_map;
74
75         HashTable<void *, SnapVector<ConcretePredicate *> *, uintptr_t, 0> * loc_waiting_writes_map;
76         /* The write values each paused thread is waiting for */
77         SnapVector<ConcretePredicate *> * thrd_waiting_write;
78         SnapVector<WaitObj *> * thrd_wait_obj;
79
80         /* A run-time map from FuncInst to ModelAction per thread, per FuncNode.
81          * Manipulated by FuncNode, and needed by NewFuzzer */
82         HashTable<uint32_t, SnapVector<inst_act_map_t *> *, int, 0> * func_inst_act_maps;
83
84         bool skip_action(ModelAction * act, SnapList<ModelAction *> * curr_act_list);
85         void monitor_waiting_thread(uint32_t func_id, thread_id_t tid);
86         void monitor_waiting_thread_counter(thread_id_t tid);
87 };
88
89 #endif  /* __HISTORY_H__ */