add a dummy predicate entry node to make code simpler; back edges are also added
[c11tester.git] / funcinst.cc
1 #include "funcinst.h"
2
3 FuncInst::FuncInst(ModelAction *act, FuncNode *func_node) :
4         collisions()
5 {
6         ASSERT(act);
7         ASSERT(func_node);
8         this->position = act->get_position();
9         this->location = act->get_location();
10         this->type = act->get_type();
11         this->order = act->get_mo();
12         this->func_node = func_node;
13 }
14
15 /* @param other Preceding FuncInst in the same execution trace
16  * Add other to predecessors if it has been added
17  *
18  * @return false: other is already in predecessors
19  *         true : other is added to precedessors
20  */
21 bool FuncInst::add_pred(FuncInst * other)
22 {
23         mllnode<FuncInst*> * it;
24         for (it = predecessors.begin();it != NULL;it=it->getNext()) {
25                 FuncInst * inst = it->getVal();
26                 if (inst == other)
27                         return false;
28         }
29
30         predecessors.push_back(other);
31         return true;
32 }
33
34 bool FuncInst::add_succ(FuncInst * other)
35 {
36         mllnode<FuncInst*>* it;
37         for (it = successors.begin();it != NULL;it=it->getNext()) {
38                 FuncInst * inst = it->getVal();
39                 if ( inst == other )
40                         return false;
41         }
42
43         successors.push_back(other);
44         return true;
45 }
46
47 FuncInst * FuncInst::search_in_collision(ModelAction *act)
48 {
49         action_type type = act->get_type();
50
51         mllnode<FuncInst*> * it;
52         for (it = collisions.begin(); it != NULL; it = it->getNext()) {
53                 FuncInst * inst = it->getVal();
54                 if (inst->get_type() == type)
55                         return inst;
56         }
57         return NULL;
58 }
59
60 bool FuncInst::is_read() const
61 {
62         return type == ATOMIC_READ || type == ATOMIC_RMWR || type == ATOMIC_RMWRCAS || type == ATOMIC_RMW;
63 }
64
65 bool FuncInst::is_write() const
66 {
67         return type == ATOMIC_WRITE || type == ATOMIC_RMW || type == ATOMIC_INIT || type == ATOMIC_UNINIT || type == NONATOMIC_WRITE;
68 }
69
70 void FuncInst::print()
71 {
72         model_print("func inst - pos: %s, loc: %p, type: %d,\n", position, location, type);
73 }