From: weiyu Date: Mon, 8 Jul 2019 23:10:17 +0000 (-0700) Subject: factor out codes for FuncInst class X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=commitdiff_plain;h=252be3e5cabb3ea9372aa03dae8d5e79207ba1c4 factor out codes for FuncInst class --- diff --git a/funcinst.cc b/funcinst.cc new file mode 100644 index 00000000..28754891 --- /dev/null +++ b/funcinst.cc @@ -0,0 +1,46 @@ +#include "funcinst.h" + +FuncInst::FuncInst(ModelAction *act) : + collisions() +{ + ASSERT(act); + this->position = act->get_position(); + this->location = act->get_location(); + this->type = act->get_type(); +} + +bool FuncInst::add_pred(FuncInst * other) { + func_inst_list_mt::iterator it; + for (it = predecessors.begin(); it != predecessors.end(); it++) { + FuncInst * inst = *it; + if (inst == other) + return false; + } + + predecessors.push_back(other); + return true; +} + +bool FuncInst::add_succ(FuncInst * other) { + func_inst_list_mt::iterator it; + for (it = successors.begin(); it != successors.end(); it++) { + FuncInst * inst = *it; + if ( inst == other ) + return false; + } + + successors.push_back(other); + return true; +} + +FuncInst * FuncInst::search_in_collision(ModelAction *act) { + action_type type = act->get_type(); + + func_inst_list_mt::iterator it; + for (it = collisions.begin(); it != collisions.end(); it++) { + FuncInst * inst = *it; + if ( inst->get_type() == type ) + return inst; + } + return NULL; +} diff --git a/funcinst.h b/funcinst.h new file mode 100644 index 00000000..3f2307e1 --- /dev/null +++ b/funcinst.h @@ -0,0 +1,37 @@ +#include "action.h" +#include "hashtable.h" + +class ModelAction; + +typedef ModelList func_inst_list_mt; + +class FuncInst { +public: + FuncInst(ModelAction *act); + ~FuncInst(); + + //ModelAction * get_action() const { return action; } + const char * get_position() const { return position; } + void * get_location() const { return location; } + action_type get_type() const { return type; } + + bool add_pred(FuncInst * other); + bool add_succ(FuncInst * other); + + FuncInst * search_in_collision(ModelAction *act); + + func_inst_list_mt * get_collisions() { return &collisions; } + func_inst_list_mt * get_preds() { return &predecessors; } + func_inst_list_mt * get_succs() { return &successors; } + + MEMALLOC +private: + //ModelAction * const action; + const char * position; + void *location; + action_type type; + + func_inst_list_mt collisions; + func_inst_list_mt predecessors; + func_inst_list_mt successors; +}; diff --git a/funcnode.cc b/funcnode.cc index d03b09a2..1fadc3b4 100644 --- a/funcnode.cc +++ b/funcnode.cc @@ -1,21 +1,12 @@ #include "funcnode.h" -FuncInst::FuncInst(ModelAction *act) : - collisions() -{ - ASSERT(act); - this->position = act->get_position(); - this->location = act->get_location(); - this->type = act->get_type(); -} - FuncNode::FuncNode() : func_insts(), inst_list(), entry_insts() {} -void FuncNode::add_action(ModelAction *act) +FuncInst * FuncNode::get_or_add_action(ModelAction *act) { ASSERT(act); @@ -27,30 +18,35 @@ void FuncNode::add_action(ModelAction *act) * source line numbers */ if (position == NULL) { - return; + return NULL; } if ( func_insts.contains(position) ) { FuncInst * inst = func_insts.get(position); if (inst->get_type() != act->get_type() ) { - model_print("action with a different type occurs at line number %s\n", position); + // model_print("action with a different type occurs at line number %s\n", position); FuncInst * func_inst = inst->search_in_collision(act); - if (func_inst != NULL) - return; + if (func_inst != NULL) { + // return the FuncInst found in the collision list + return func_inst; + } func_inst = new FuncInst(act); inst->get_collisions()->push_back(func_inst); inst_list.push_back(func_inst); // delete? - model_print("collision added\n"); + // model_print("collision added\n"); + + return func_inst; } - return; + return inst; } FuncInst * func_inst = new FuncInst(act); func_insts.put(position, func_inst); inst_list.push_back(func_inst); + return func_inst; } diff --git a/funcnode.h b/funcnode.h index 25e22083..eb7bc794 100644 --- a/funcnode.h +++ b/funcnode.h @@ -1,53 +1,20 @@ #include "action.h" +#include "funcinst.h" #include "hashtable.h" class ModelAction; -typedef ModelList func_inst_list_t; - -class FuncInst { -public: - FuncInst(ModelAction *act); - ~FuncInst(); - - //ModelAction * get_action() const { return action; } - const char * get_position() const { return position; } - void * get_location() const { return location; } - action_type get_type() const { return type; } - - func_inst_list_t * get_collisions() { return &collisions; } - - FuncInst * search_in_collision(ModelAction *act) { - action_type type = act->get_type(); - - func_inst_list_t::iterator it; - for (it = collisions.begin(); it != collisions.end(); it++) { - FuncInst * inst = *it; - if ( inst->get_type() == type ) - return inst; - } - return NULL; - } - - MEMALLOC -private: - //ModelAction * const action; - const char * position; - void *location; - action_type type; - - func_inst_list_t collisions; -}; +typedef ModelList func_inst_list_mt; class FuncNode { public: FuncNode(); ~FuncNode(); - void add_action(ModelAction *act); + FuncInst * get_or_add_action(ModelAction *act); HashTable * getFuncInsts() { return &func_insts; } - func_inst_list_t * get_inst_list() { return &inst_list; } + func_inst_list_mt * get_inst_list() { return &inst_list; } uint32_t get_func_id() { return func_id; } const char * get_func_name() { return func_name; } @@ -68,8 +35,8 @@ private: HashTable func_insts; /* list of all atomic instructions in this function */ - func_inst_list_t inst_list; + func_inst_list_mt inst_list; /* possible entry (atomic) instructions in this function */ - func_inst_list_t entry_insts; + func_inst_list_mt entry_insts; };