More work towards freeing old ModelActions
[c11tester.git] / funcinst.cc
1 #include "funcinst.h"
2 #include "model.h"
3
4 FuncInst::FuncInst(ModelAction *act, FuncNode *func_node) :
5         single_location(true),
6         execution_number(0),
7         action_marker(0)        /* The marker for FuncNode starts from 1 */
8 {
9         ASSERT(act);
10         ASSERT(func_node);
11         this->position = act->get_position();
12         this->location = act->get_location();
13         this->type = act->get_type();
14         this->order = act->get_mo();
15         this->func_node = func_node;
16 }
17
18 /* @param other Preceding FuncInst in the same execution trace
19  * Add other to predecessors if it has been added
20  *
21  * @return false: other is already in predecessors
22  *         true : other is added to precedessors
23  */
24 bool FuncInst::add_pred(FuncInst * other)
25 {
26         mllnode<FuncInst*> * it;
27         for (it = predecessors.begin();it != NULL;it=it->getNext()) {
28                 FuncInst * inst = it->getVal();
29                 if (inst == other)
30                         return false;
31         }
32
33         predecessors.push_back(other);
34         return true;
35 }
36
37 bool FuncInst::add_succ(FuncInst * other)
38 {
39         mllnode<FuncInst*>* it;
40         for (it = successors.begin();it != NULL;it=it->getNext()) {
41                 FuncInst * inst = it->getVal();
42                 if ( inst == other )
43                         return false;
44         }
45
46         successors.push_back(other);
47         return true;
48 }
49
50 void FuncInst::set_associated_act(ModelAction * act, uint32_t marker)
51 {
52         associated_act = act;
53         action_marker = marker;
54 }
55
56 ModelAction * FuncInst::get_associated_act(uint32_t marker)
57 {
58         if (action_marker == marker)
59                 return associated_act;
60         else
61                 return NULL;
62 }
63
64 /* Search the FuncInst that has the same type as act in the collision list */
65 FuncInst * FuncInst::search_in_collision(ModelAction *act)
66 {
67         action_type type = act->get_type();
68
69         mllnode<FuncInst*> * it;
70         for (it = collisions.begin();it != NULL;it = it->getNext()) {
71                 FuncInst * inst = it->getVal();
72                 if (inst->get_type() == type)
73                         return inst;
74         }
75         return NULL;
76 }
77
78 void FuncInst::add_to_collision(FuncInst * inst)
79 {
80         collisions.push_back(inst);
81 }
82
83 /* Note: is_read() is equivalent to ModelAction::is_read() */
84 bool FuncInst::is_read() const
85 {
86         return type == ATOMIC_READ || type == ATOMIC_RMWR || type == ATOMIC_RMWRCAS || type == ATOMIC_RMW;
87 }
88
89 /* Note: because of action type conversion in ModelExecution
90  * is_write() <==> pure writes (excluding rmw) */
91 bool FuncInst::is_write() const
92 {
93         return type == ATOMIC_WRITE || type == ATOMIC_RMW || type == ATOMIC_INIT || type == NONATOMIC_WRITE;
94 }
95
96 void FuncInst::print()
97 {
98         model_print("func inst - pos: %s, loc: %p, type: %d,\n", position, location, type);
99 }