00001
00026 #ifndef LOGICGATE_H_
00027 #define LOGICGATE_H_
00028
00029 #include <string>
00030 #include <iostream>
00031
00032 #include <cstdlib>
00033 #include <cassert>
00034
00035 #include "Galois/Graphs/Graph.h"
00036
00037
00038 #include "Event.h"
00039 #include "AbstractSimObject.h"
00040 #include "SimObject.h"
00041 #include "BaseLogicGate.h"
00042 #include "logicDefs.h"
00043 #include "LogicUpdate.h"
00044
00048 class LogicGate: public AbstractSimObject, public BaseLogicGate {
00049
00050 public:
00051 typedef EventTy::Type EventKind;
00052
00053 LogicGate (size_t id, size_t numOutputs, size_t numInputs, SimTime delay): AbstractSimObject (id, numOutputs, numInputs), BaseLogicGate (delay) {}
00054
00055 LogicGate (const LogicGate& that): AbstractSimObject (that), BaseLogicGate (that) {}
00056
00063 virtual size_t getInputIndex(const std::string& net) const = 0;
00064
00065 protected:
00071 void netNameMismatch (const LogicUpdate& le) const {
00072 std::cerr << "Received logic update : " << le.toString () << " with mismatching net name, this = " <<
00073 AbstractSimObject::toString () << std::endl;
00074 exit (-1);
00075 }
00076
00086 void sendEventsToFanout(Graph& graph, GNode& myNode, const EventTy& inputEvent,
00087 const EventKind& type, const LogicUpdate& msg) {
00088
00089
00090
00091 SimObject* srcObj = graph.getData (myNode, Galois::NONE);
00092 assert (srcObj == this);
00093
00094 SimTime sendTime = inputEvent.getRecvTime();
00095
00096 for (Graph::neighbor_iterator i = graph.neighbor_begin (myNode, Galois::NONE),
00097 e = graph.neighbor_end (myNode, Galois::NONE); i != e; ++i) {
00098
00099 const GNode& dst = *i;
00100 SimObject* dstObj = graph.getData (dst, Galois::NONE);
00101
00102 EventTy ne = srcObj->makeEvent (srcObj, dstObj, type, msg, sendTime,
00103 BaseLogicGate::getDelay ());
00104
00105
00106 LogicGate* dstGate = dynamic_cast< LogicGate* > (dstObj);
00107
00108 if (dstGate == NULL) {
00109 std::cerr << "dynamic_cast failed" << std::endl;
00110 abort ();
00111
00112 } else {
00113 const std::string& outNet = getOutputName();
00114 size_t dstIn = dstGate->getInputIndex(outNet);
00115 dstGate->recvEvent(dstIn, ne);
00116 }
00117
00118
00119 }
00120
00121
00122 }
00123
00124 };
00125
00126 #endif