Add the simulation class and start populating it.
This commit is contained in:
88
src/Simulation.cpp
Normal file
88
src/Simulation.cpp
Normal file
@@ -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()
|
||||
{
|
||||
}
|
32
src/Simulation.h
Normal file
32
src/Simulation.h
Normal file
@@ -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 <string>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class Simulation {
|
||||
public:
|
||||
bool parse(string fileName);
|
||||
void simulate();
|
||||
void print();
|
||||
private:
|
||||
priority_queue<event> e;
|
||||
vector<gate*> gates;
|
||||
vector<wire*> wires;
|
||||
};
|
||||
|
||||
#endif // !SIMULATION
|
@@ -11,7 +11,7 @@ class gate {
|
||||
wire *in1, *in2, *out;
|
||||
priority_queue<event> *e;
|
||||
int delay;
|
||||
priority_queue<event> *e;
|
||||
|
||||
};
|
||||
|
||||
#endif // !GATE
|
||||
|
Reference in New Issue
Block a user