Separate the marking algorithm and action removal algorithm
[c11tester.git] / funcnode.cc
index dc903ef82a49782f857c870a47ff793a9578aec1..4172f4175403ae5ffa6117d4ff5a40a0b85eedc0 100644 (file)
@@ -184,6 +184,22 @@ void FuncNode::update_tree(action_list_t * act_list)
 
        for (sllnode<ModelAction *> * it = act_list->begin();it != NULL;it = it->getNext()) {
                ModelAction * act = it->getVal();
+
+               if (act->get_original_type() != ATOMIC_NOP && act->get_swap_flag() == false)
+                       act->use_original_type();
+
+               // Remove func_act_ref so that actions can be deleted by Execution::collectActions
+               if (act->is_read()) {
+                       // For every read or rmw actions in this list, the reads_from was marked, and not deleted.
+                       // So it is safe to call get_reads_from
+                       ModelAction * rf = act->get_reads_from();
+                       if (rf->get_original_type() != ATOMIC_NOP && rf->get_swap_flag() == false)
+                               rf->use_original_type();
+
+                       rf->setFuncActRef(NULL);
+               }
+               act->setFuncActRef(NULL);
+
                FuncInst * func_inst = get_inst(act);
                void * loc = act->get_location();
 
@@ -222,12 +238,40 @@ void FuncNode::update_tree(action_list_t * act_list)
                }
        }
 
-//     model_print("function %s\n", func_name);
-//     print_val_loc_map();
-
        update_inst_tree(&inst_list);
        update_predicate_tree(&rw_act_list);
 
+       // Revert back action types and free
+       for (sllnode<ModelAction *> * it = act_list->begin(); it != NULL;) {
+               ModelAction * act = it->getVal();
+               // Do iteration early in case we delete act
+               it = it->getNext();
+
+               // Revert back action types for actions whose types have been changed. 
+               if (act->is_read()) {
+                       ModelAction * rf = act->get_reads_from();
+                       if (rf->get_swap_flag() == true)
+                               rf->use_original_type();
+               }
+
+               if (act->get_swap_flag() == true)
+                       act->use_original_type();
+
+               if (act->is_free()) {
+                       // TODO
+               } else if (act->is_read()) {
+                       if (act->is_rmw()) {
+                               // reads_from can not be READY_FREE
+                       } else {
+                               ModelAction *rf = act->get_reads_from();
+                               if (rf->is_free()) {
+                                       model_print("delete read %d; %p\n", act->get_seq_number(), act);
+                                       delete act;
+                               }
+                       }
+               }
+       }
+
 //     print_predicate_tree();
 }