add func_map_rev to map function ids to function names
[c11tester.git] / funcnode.h
1 #include "action.h"
2 #include "hashtable.h"
3
4 class ModelAction;
5
6 typedef ModelList<FuncInst *> func_inst_list_t;
7
8 class FuncInst {
9 public:
10         FuncInst(ModelAction *act);
11         ~FuncInst();
12
13         //ModelAction * get_action() const { return action; }
14         const char * get_position() const { return position; }
15         void * get_location() const { return location; }
16         action_type get_type() const { return type; }
17
18         func_inst_list_t * get_collisions() { return &collisions; }
19
20         FuncInst * search_in_collision(ModelAction *act) {
21                 action_type type = act->get_type();
22
23                 func_inst_list_t::iterator it;
24                 for (it = collisions.begin(); it != collisions.end(); it++) {
25                         FuncInst * inst = *it;
26                         if ( inst->get_type() == type )
27                                 return inst;
28                 }
29                 return NULL;
30         }
31
32         MEMALLOC
33 private:
34         //ModelAction * const action;
35         const char * position;
36         void *location;
37         action_type type;
38
39         func_inst_list_t collisions;
40 };
41
42 class FuncNode {
43 public:
44         FuncNode();
45         ~FuncNode();
46
47         void add_action(ModelAction *act);
48
49         HashTable<const char *, FuncInst *, uintptr_t, 4, model_malloc, model_calloc, model_free> * getFuncInsts() { return &func_insts; }
50         func_inst_list_t * get_inst_list() { return &inst_list; }
51
52         uint32_t get_func_id() { return func_id; }
53         const char * get_func_name() { return func_name; }
54         void set_func_id(uint32_t id) { func_id = id; }
55         void set_func_name(const char * name) { func_name = name; }
56
57         MEMALLOC
58 private:
59         uint32_t func_id;
60         const char * func_name;
61
62         /* Use source line number as the key of hashtable, to check if 
63          * atomic operation with this line number has been added or not
64          *
65          * To do: cds_atomic_compare_exchange contains three atomic operations
66          * that are feeded with the same source line number by llvm pass
67          */
68         HashTable<const char *, FuncInst *, uintptr_t, 4, model_malloc, model_calloc, model_free> func_insts;
69
70         /* list of all atomic instructions in this function */
71         func_inst_list_t inst_list;
72
73         /* possible entry (atomic) instructions in this function */
74         func_inst_list_t entry_insts;
75 };