From c4c62ed53bdb206211ec6b0e304ae3f831121e48 Mon Sep 17 00:00:00 2001 From: Joel Beckmeyer Date: Mon, 24 Apr 2017 20:14:22 -0400 Subject: [PATCH 1/2] Implement simulate() --- src/Simulation.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index edf68c4..7abeb0b 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -109,8 +109,28 @@ bool Simulation::parseVector(string fileName) { } } -void Simulation::simulate() -{ +void Simulation::simulate() { + // loop through event queue + while(!e.empty()) { + bool doesChange; + Wire * output; + + Event tmpEvent = e.top(); + e.pop(); + + output = tmpEvent.getOutput(); + doesChange = output->setValue(tmpEvent.getValue(), tmpEvent.getTime()); + + // if the wire value changes, evaluate gates + if(doesChange) { + Gate * tmpGate; + int index = 0; + do{ + tmpGate = output->getGate(index++); + tmpGate->evaluate(tmpEvent.evTime); + }while(tmpGate != nullptr); + } + } } void Simulation::print() From 081330103c8119fd3ca3ab9c5b4c339366cdae76 Mon Sep 17 00:00:00 2001 From: Joel Beckmeyer Date: Mon, 24 Apr 2017 20:24:39 -0400 Subject: [PATCH 2/2] implement print() and fix simulate() --- src/Simulation.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Simulation.cpp b/src/Simulation.cpp index 7abeb0b..50e786b 100644 --- a/src/Simulation.cpp +++ b/src/Simulation.cpp @@ -127,7 +127,7 @@ void Simulation::simulate() { int index = 0; do{ tmpGate = output->getGate(index++); - tmpGate->evaluate(tmpEvent.evTime); + e.push(tmpGate->evaluate(tmpEvent.evTime)); }while(tmpGate != nullptr); } } @@ -135,6 +135,10 @@ void Simulation::simulate() { void Simulation::print() { + // iterate through wires, printing each of them + for(auto i = wires.begin(); i != wires.end(); ++i) { + cout << *i; + } } Wire * Simulation::findWire(int n)