remove print statements
[c11tester.git] / funcnode.cc
index d45c8a8fe1136027a97027fcb029fe3f420c66ff..8e76ebc674bf8e6d7339b45768b6a8b87c0a961d 100644 (file)
@@ -3,10 +3,12 @@
 FuncNode::FuncNode() :
        func_inst_map(),
        inst_list(),
-       entry_insts()
+       entry_insts(),
+       thrd_read_map(),
+       read_locations()
 {}
 
-/* Check whether FuncInst with the same type, position, and location 
+/* Check whether FuncInst with the same type, position, and location
  * as act has been added to func_inst_map or not. If so, return it;
  * if not, add it and return it.
  *
@@ -38,7 +40,7 @@ FuncInst * FuncNode::get_or_add_action(ModelAction *act)
 
                        func_inst = new FuncInst(act, this);
                        inst->get_collisions()->push_back(func_inst);
-                       inst_list.push_back(func_inst);         // delete?
+                       inst_list.push_back(func_inst); // delete?
 
                        return func_inst;
                }
@@ -60,7 +62,7 @@ void FuncNode::add_entry_inst(FuncInst * inst)
                return;
 
        func_inst_list_mt::iterator it;
-       for (it = entry_insts.begin(); it != entry_insts.end(); it++) {
+       for (it = entry_insts.begin();it != entry_insts.end();it++) {
                if (inst == *it)
                        return;
        }
@@ -68,7 +70,41 @@ void FuncNode::add_entry_inst(FuncInst * inst)
        entry_insts.push_back(inst);
 }
 
-/* Store the values read by atomic read actions into loc_thrd_read_map */
+/* @param inst_list a list of FuncInsts; this argument comes from ModelExecution
+ * Link FuncInsts in a list - add one FuncInst to another's predecessors and successors
+ */
+void FuncNode::link_insts(func_inst_list_t * inst_list)
+{
+       if (inst_list == NULL)
+               return;
+
+       func_inst_list_t::iterator it = inst_list->begin();
+       func_inst_list_t::iterator prev;
+
+       if (inst_list->size() == 0)
+               return;
+
+       /* add the first instruction to the list of entry insts */
+       FuncInst * entry_inst = *it;
+       add_entry_inst(entry_inst);
+
+       it++;
+       while (it != inst_list->end()) {
+               prev = it;
+               prev--;
+
+               FuncInst * prev_inst = *prev;
+               FuncInst * curr_inst = *it;
+
+               prev_inst->add_succ(curr_inst);
+               curr_inst->add_pred(prev_inst);
+
+               it++;
+       }
+}
+
+/* @param tid thread id
+ * Store the values read by atomic read actions into thrd_read_map */
 void FuncNode::store_read(ModelAction * act, uint32_t tid)
 {
        ASSERT(act);
@@ -76,21 +112,21 @@ void FuncNode::store_read(ModelAction * act, uint32_t tid)
        void * location = act->get_location();
        uint64_t read_from_val = act->get_reads_from_value();
 
-       ModelVector<uint64_t> * read_vals = loc_thrd_read_map.get(location);
-       if (read_vals == NULL) {
-               read_vals = new ModelVector<uint64_t>();
-               loc_thrd_read_map.put(location, read_vals);
-       }
+       if (thrd_read_map.size() <= tid)
+               thrd_read_map.resize(tid + 1);
 
-       if (read_vals->size() <= tid) {
-               read_vals->resize(tid + 1);
+       read_map_t * read_map = thrd_read_map[tid];
+       if (read_map == NULL) {
+               read_map = new read_map_t();
+               thrd_read_map[tid] = read_map;
        }
-       read_vals->at(tid) = read_from_val;
 
-       /* Store keys of loc_thrd_read_map into read_locations */
+       read_map->put(location, read_from_val);
+
+       /* Store the memory locations where atomic reads happen */
        bool push_loc = true;
        ModelList<void *>::iterator it;
-       for (it = read_locations.begin(); it != read_locations.end(); it++) {
+       for (it = read_locations.begin();it != read_locations.end();it++) {
                if (location == *it) {
                        push_loc = false;
                        break;
@@ -101,18 +137,48 @@ void FuncNode::store_read(ModelAction * act, uint32_t tid)
                read_locations.push_back(location);
 }
 
+uint64_t FuncNode::query_last_read(ModelAction * act, uint32_t tid)
+{
+       if (thrd_read_map.size() <= tid)
+               return 0xdeadbeef;
+
+       read_map_t * read_map = thrd_read_map[tid];
+       void * location = act->get_location();
+
+       /* last read value not found */
+       if ( !read_map->contains(location) )
+               return 0xdeadbeef;
+
+       uint64_t read_val = read_map->get(location);
+       return read_val;
+}
+
 /* @param tid thread id
- * Print the values read by the last read actions per memory location
+ * Reset read map for a thread. This function shall only be called
+ * when a thread exits a function
+ */
+void FuncNode::clear_read_map(uint32_t tid)
+{
+       if (thrd_read_map.size() <= tid)
+               return;
+
+       thrd_read_map[tid]->reset();
+}
+
+/* @param tid thread id
+ * Print the values read by the last read actions for each memory location
  */
 void FuncNode::print_last_read(uint32_t tid)
 {
+       ASSERT(thrd_read_map.size() > tid);
+       read_map_t * read_map = thrd_read_map[tid];
+
        ModelList<void *>::iterator it;
-       for (it = read_locations.begin(); it != read_locations.end(); it++) {
-               ModelVector<uint64_t> * read_vals = loc_thrd_read_map.get(*it);
-               if (read_vals->size() <= tid)
+       for (it = read_locations.begin();it != read_locations.end();it++) {
+               if ( !read_map->contains(*it) )
                        break;
 
-               int64_t read_val = read_vals->at(tid);
+               uint64_t read_val = read_map->get(*it);
                model_print("last read of thread %d at %p: 0x%x\n", tid, *it, read_val);
        }
 }