X-Git-Url: http://plrg.eecs.uci.edu/git/?p=model-checker.git;a=blobdiff_plain;f=cyclegraph.h;h=a2cb93d7ca702217be5af879cbf0c2ba34f9a67e;hp=83d3db21d77cdfc192f0bd286d21fee188de7fac;hb=0d09bdcb6b3c438693e68787c3cd4bb97aa87eee;hpb=ff29187c639cdb032debdb036d2c9062f77879b0 diff --git a/cyclegraph.h b/cyclegraph.h index 83d3db2..a2cb93d 100644 --- a/cyclegraph.h +++ b/cyclegraph.h @@ -9,9 +9,11 @@ #ifndef __CYCLEGRAPH_H__ #define __CYCLEGRAPH_H__ -#include "hashtable.h" #include #include +#include + +#include "hashtable.h" #include "config.h" #include "mymemory.h" @@ -28,14 +30,16 @@ class CycleGraph { ~CycleGraph(); template - void addEdge(const T from, const U to); + bool addEdge(const T *from, const U *to); + + template + void addRMWEdge(const T *from, const ModelAction *rmw); bool checkForCycles() const; - void addRMWEdge(const ModelAction *from, const ModelAction *rmw); bool checkPromise(const ModelAction *from, Promise *p) const; - template - bool checkReachable(const ModelAction *from, const T *to) const; + template + bool checkReachable(const T *from, const U *to) const; void startChanges(); void commitChanges(); @@ -43,15 +47,21 @@ class CycleGraph { #if SUPPORT_MOD_ORDER_DUMP void dumpNodes(FILE *file) const; void dumpGraphToFile(const char *filename) const; + + void dot_print_node(FILE *file, const ModelAction *act); + template + void dot_print_edge(FILE *file, const T *from, const U *to, const char *prop); #endif - bool resolvePromise(ModelAction *reader, ModelAction *writer, + bool resolvePromise(const Promise *promise, ModelAction *writer, promise_list_t *mustResolve); SNAPSHOTALLOC private: - void addNodeEdge(CycleNode *fromnode, CycleNode *tonode); + bool addNodeEdge(CycleNode *fromnode, CycleNode *tonode); void putNode(const ModelAction *act, CycleNode *node); + void putNode(const Promise *promise, CycleNode *node); + void erasePromiseNode(const Promise *promise); CycleNode * getNode(const ModelAction *act); CycleNode * getNode(const Promise *promise); CycleNode * getNode_noCreate(const ModelAction *act) const; @@ -63,12 +73,11 @@ class CycleGraph { /** @brief A table for mapping ModelActions to CycleNodes */ HashTable actionToNode; - /** @brief A table for mapping reader ModelActions to Promise - * CycleNodes */ - HashTable readerToPromiseNode; + /** @brief A table for mapping Promises to CycleNodes */ + HashTable promiseToNode; #if SUPPORT_MOD_ORDER_DUMP - std::vector nodeList; + std::vector< CycleNode *, SnapshotAlloc > nodeList; #endif bool checkReachable(const CycleNode *from, const CycleNode *to) const; @@ -102,11 +111,6 @@ class CycleNode { void clearRMW() { hasRMW = NULL; } const ModelAction * getAction() const { return action; } const Promise * getPromise() const { return promise; } - - void popEdge() { - edges.pop_back(); - } - bool is_promise() const { return !action; } void resolvePromise(const ModelAction *writer); @@ -130,46 +134,4 @@ class CycleNode { CycleNode *hasRMW; }; -/* - * @brief Adds an edge between objects - * - * This function will add an edge between any two objects which can be - * associated with a CycleNode. That is, if they have a CycleGraph::getNode - * implementation. - * - * The object to is ordered after the object from. - * - * @param to The edge points to this object, of type T - * @param from The edge comes from this object, of type U - */ -template -void CycleGraph::addEdge(const T from, const U to) -{ - ASSERT(from); - ASSERT(to); - - CycleNode *fromnode = getNode(from); - CycleNode *tonode = getNode(to); - - addNodeEdge(fromnode, tonode); -} - -/** - * Checks whether one ModelAction can reach another ModelAction/Promise - * @param from The ModelAction from which to begin exploration - * @param to The ModelAction or Promise to reach - * @return True, @a from can reach @a to; otherwise, false - */ -template -bool CycleGraph::checkReachable(const ModelAction *from, const T *to) const -{ - CycleNode *fromnode = getNode_noCreate(from); - CycleNode *tonode = getNode_noCreate(to); - - if (!fromnode || !tonode) - return false; - - return checkReachable(fromnode, tonode); -} - #endif /* __CYCLEGRAPH_H__ */