--- /dev/null
+#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;
+}
--- /dev/null
+#include "action.h"
+#include "hashtable.h"
+
+class ModelAction;
+
+typedef ModelList<FuncInst *> 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;
+};
#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);
* 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;
}
#include "action.h"
+#include "funcinst.h"
#include "hashtable.h"
class ModelAction;
-typedef ModelList<FuncInst *> 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<FuncInst *> func_inst_list_mt;
class FuncNode {
public:
FuncNode();
~FuncNode();
- void add_action(ModelAction *act);
+ FuncInst * get_or_add_action(ModelAction *act);
HashTable<const char *, FuncInst *, uintptr_t, 4, model_malloc, model_calloc, model_free> * 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; }
HashTable<const char *, FuncInst *, uintptr_t, 4, model_malloc, model_calloc, model_free> 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;
};