From a5e16c934795f9959bf70851817ecbd704c8f1c0 Mon Sep 17 00:00:00 2001 From: daniel Date: Thu, 20 Apr 2017 12:41:43 -0400 Subject: [PATCH] Add the simulation class and start populating it. --- Radec/Radec/Radec.vcxproj | 5 +- Radec/Radec/Radec.vcxproj.filters | 15 +++--- src/Simulation.cpp | 88 +++++++++++++++++++++++++++++++ src/Simulation.h | 32 +++++++++++ src/gate.h | 2 +- 5 files changed, 133 insertions(+), 9 deletions(-) create mode 100644 src/Simulation.cpp create mode 100644 src/Simulation.h diff --git a/Radec/Radec/Radec.vcxproj b/Radec/Radec/Radec.vcxproj index 43f9dbb..dbad149 100644 --- a/Radec/Radec/Radec.vcxproj +++ b/Radec/Radec/Radec.vcxproj @@ -153,7 +153,7 @@ - + @@ -166,7 +166,8 @@ - + + diff --git a/Radec/Radec/Radec.vcxproj.filters b/Radec/Radec/Radec.vcxproj.filters index 6171174..e0434bd 100644 --- a/Radec/Radec/Radec.vcxproj.filters +++ b/Radec/Radec/Radec.vcxproj.filters @@ -30,9 +30,6 @@ Header Files - - Header Files - Header Files\Gates @@ -54,6 +51,9 @@ Header Files\Gates + + Header Files + @@ -62,9 +62,6 @@ Source Files - - Source Files - Source Files\Gates @@ -89,5 +86,11 @@ Source Files\Gates + + Source Files + + + Source Files + \ No newline at end of file diff --git a/src/Simulation.cpp b/src/Simulation.cpp new file mode 100644 index 0000000..e643a1e --- /dev/null +++ b/src/Simulation.cpp @@ -0,0 +1,88 @@ +#include "Simulation.h" + +bool Simulation::parse(string fileName) +{ + ifstream in; + circuit.open(fileName + ".txt"); + if (in.fail()) { + cerr << endl << fileName << ".txt could not be opened :("; + exit(1); + } + + string tmpString, tmpType; + int tmp1, tmp2, tmp3; + wire *tmpWire; + gate *tmpGate; + getline(in, tmpString); + + while (!in.eof()) { + tmpType << in; + + tmpString << in; + tmp1 << in; + if (tmpType == "INPUT") { + tmpWire = new wire(tmp1, true, tmpString); + wires.push_back(tmpWire); + } + else if (tmpType == "OUTPUT") { + tmpWire = new wire(tmp1, false, tmpString); + wires.push_back(tmpWire); + } + else if (tmpType == "NOT") { + tmp2 << in; + tmpGate = new notGate(getDelay(tmpString), findWire(tmp1), + findWire(tmp2)); + gates.push_back(tmpGate); + } + else if (tmpType == "AND") { + tmp2 << in; + tmp3 << in; + tmpGate = new andGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), + findWire(tmp3)); + gates.push_back(tmpGate); + } + else if (tmpType == "NAND") { + tmp2 << in; + tmp3 << in; + tmpGate = new nandGate(getDelay(tmpString), findWire(tmp1), + findWire(tmp2), findWire(tmp3)); + gates.push_back(tmpGate); + } + else if (tmpType == "OR") { + tmp2 << in; + tmp3 << in; + tmpGate = new orGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), + findWire(tmp3)); + gates.push_back(tmpGate); + } + else if (tmpType == "XOR") { + tmp2 << in; + tmp3 << in; + tmpGate = new xorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), + findWire(tmp3)); + gates.push_back(tmpGate); + } + else if (tmpType == "NOR") { + tmp2 << in; + tmp3 << in; + tmpGate = new norGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), + findWire(tmp3)); + gates.push_back(tmpGate); + } + else if (tmpType == "XNOR") { + tmp2 << in; + tmp3 << in; + tmpGate = new xnorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2), + findWire(tmp3)); + gates.push_back(tmpGate); + } + } +} + +void Simulation::simulate() +{ +} + +void Simulation::print() +{ +} diff --git a/src/Simulation.h b/src/Simulation.h new file mode 100644 index 0000000..ac2f5f7 --- /dev/null +++ b/src/Simulation.h @@ -0,0 +1,32 @@ +#ifndef SIMULATION +#define SIMULATION + +#include "wire.h" +#include "event.h" +#include "gate.h" +#include "andGate.h" +#include "nandGate.h" +#include "orGate.h" +#include "norGate.h" +#include "xnorGate.h" +#include "xorGate.h" +#include "notGate.h" +#include +#include +#include +#include + +using namespace std; + +class Simulation { + public: + bool parse(string fileName); + void simulate(); + void print(); + private: + priority_queue e; + vector gates; + vector wires; +}; + +#endif // !SIMULATION diff --git a/src/gate.h b/src/gate.h index e48e16f..501bdba 100644 --- a/src/gate.h +++ b/src/gate.h @@ -11,7 +11,7 @@ class gate { wire *in1, *in2, *out; priority_queue *e; int delay; - priority_queue *e; + }; #endif // !GATE