5a3657c44c9cf19cc1075c8fd7c00194241583c4
[c11tester.git] / history.h
1 #ifndef __HISTORY_H__
2 #define __HISTORY_H__
3
4 #include "stl-model.h"
5 #include "common.h"
6 #include "classlist.h"
7 #include "hashtable.h"
8 #include "threads-model.h"
9
10 class ModelHistory {
11 public:
12         ModelHistory();
13         ~ModelHistory();
14
15         void enter_function(const uint32_t func_id, thread_id_t tid);
16         void exit_function(const uint32_t func_id, thread_id_t tid);
17
18         uint32_t get_func_counter() { return func_counter; }
19         void incr_func_counter() { func_counter++; }
20
21         void resize_func_nodes(uint32_t max_func_id);
22         void process_action(ModelAction *act, thread_id_t tid);
23
24         HashTable<const char *, uint32_t, uintptr_t, 4, model_malloc, model_calloc, model_free> * getFuncMap() { return &func_map; }
25         ModelVector<const char *> * getFuncMapRev() { return &func_map_rev; }
26
27         ModelVector<FuncNode *> * getFuncNodes() { return &func_nodes; }
28         FuncNode * get_func_node(uint32_t func_id);
29         FuncNode * get_curr_func_node(thread_id_t tid);
30
31         void update_write_history(void * location, uint64_t write_val);
32         HashTable<void *, value_set_t *, uintptr_t, 4> * getWriteHistory() { return &write_history; }
33         void update_loc_func_nodes_map(void * location, FuncNode * node);
34         void update_loc_wr_func_nodes_map(void * location, FuncNode * node);
35
36         void add_waiting_write(ConcretePredicate * concrete);
37         void remove_waiting_write(thread_id_t tid);
38         void check_waiting_write(ModelAction * write_act);
39         SnapVector<ConcretePredicate *> * getThrdWaitingWrite() { return &thrd_waiting_write; }
40
41         void set_new_exec_flag();
42         void dump_func_node_graph();
43         void print_func_node();
44
45         MEMALLOC
46 private:
47         uint32_t func_counter;
48
49         /* Map function names to integer ids */
50         HashTable<const char *, uint32_t, uintptr_t, 4, model_malloc, model_calloc, model_free> func_map;
51
52         /* Map integer ids to function names */
53         ModelVector<const char *> func_map_rev;
54
55         ModelVector<FuncNode *> func_nodes;
56
57         /* Map a location to a set of values that have been written to it */
58         HashTable<void *, value_set_t *, uintptr_t, 4> write_history;
59
60         /* Map a location to FuncNodes that may read from it */
61         HashTable<void *, SnapList<FuncNode *> *, uintptr_t, 4> loc_func_nodes_map;
62
63         /* Map a location to FuncNodes that may write to it */
64         HashTable<void *, SnapList<FuncNode *> *, uintptr_t, 4> loc_wr_func_nodes_map;
65
66         /* Keeps track of the last function entered by each thread */
67         SnapVector<uint32_t> thrd_last_entered_func;
68
69         HashTable<void *, SnapVector<ConcretePredicate *> *, uintptr_t, 4> loc_waiting_writes_map;
70         SnapVector<ConcretePredicate *> thrd_waiting_write;
71 };
72
73 #endif  /* __HISTORY_H__ */