some edits to NewFuzzer
[c11tester.git] / newfuzzer.cc
1 #include "newfuzzer.h"
2 #include "threads-model.h"
3 #include "model.h"
4 #include "action.h"
5 #include "execution.h"
6 #include "funcnode.h"
7
8 /**
9  * @brief Register the ModelHistory and ModelExecution engine
10  */
11 void NewFuzzer::register_engine(ModelHistory * history, ModelExecution *execution)
12 {
13         this->history = history;
14         this->execution = execution;
15 }
16
17
18 int NewFuzzer::selectWrite(ModelAction *read, SnapVector<ModelAction *> * rf_set)
19 {
20         thread_id_t tid = read->get_tid();
21         int thread_id = id_to_int(tid);
22
23         SnapVector<func_id_list_t> * thrd_func_list = execution->get_thrd_func_list();
24         uint32_t func_id = (*thrd_func_list)[thread_id].back();
25
26         FuncNode * func_node = history->get_func_node(func_id);
27         FuncInst * read_inst = func_node->get_inst(read);
28         Predicate * curr_pred = func_node->get_predicate_tree_position(tid);
29
30         ModelVector<Predicate *> * children = curr_pred->get_children();
31         if (children->size() == 0)
32                 return random() % rf_set->size();
33
34         int random_index = random() % rf_set->size();
35         return random_index;
36 }
37