fix a bunch of compile-time errors
This commit is contained in:
parent
1832d7adff
commit
850d4e0fbd
@ -8,7 +8,7 @@ class andGate : public gate {
|
|||||||
public:
|
public:
|
||||||
andGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
andGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||||
wire* wire3);
|
wire* wire3);
|
||||||
int evaluate(int evTime);
|
void evaluate(int evTime);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !AND
|
#endif // !AND
|
||||||
|
@ -7,10 +7,10 @@ event::event(int num, int value, int setTime, wire * output){
|
|||||||
out = output;
|
out = output;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool event::operator<(const event &e1) {
|
bool operator<(const event &e1, const event &e2) {
|
||||||
if(evTime == e1.evTime) {
|
if(e1.evTime == e2.evTime) {
|
||||||
return evNum > e1.evNum;
|
return e1.evNum > e2.evNum;
|
||||||
}
|
}
|
||||||
return evTime > e1.evTime;
|
return e1.evTime > e2.evTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ using namespace std;
|
|||||||
class event {
|
class event {
|
||||||
public:
|
public:
|
||||||
event(int num, int value, int setTime, wire * output);
|
event(int num, int value, int setTime, wire * output);
|
||||||
bool operator<(const event &e1);
|
friend bool operator<(const event &e1, const event &e2);
|
||||||
private:
|
private:
|
||||||
int evNum, evValue, evTime;
|
int evNum, evValue, evTime;
|
||||||
wire *out;
|
wire *out;
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
#ifndef GATE
|
#ifndef GATE
|
||||||
#define GATE
|
#define GATE
|
||||||
|
|
||||||
|
#include "event.h"
|
||||||
|
|
||||||
class wire;
|
class wire;
|
||||||
|
|
||||||
class gate {
|
class gate {
|
||||||
public:
|
public:
|
||||||
gate();
|
gate();
|
||||||
virtual void evaluate() = 0;
|
virtual void evaluate(int) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
wire *in1, *in2, *out;
|
wire *in1, *in2, *out;
|
||||||
priority_queue<event> *e;
|
priority_queue<event> *e;
|
||||||
int delay;
|
int delay;
|
||||||
priority_queue<event> *e;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // !GATE
|
#endif // !GATE
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "wire.h"
|
#include "wire.h"
|
||||||
|
|
||||||
class norGate : public gate {
|
class norGate : public gate {
|
||||||
|
public:
|
||||||
norGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
norGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||||
wire* wire3);
|
wire* wire3);
|
||||||
void evaluate(int evTime);
|
void evaluate(int evTime);
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "event.h"
|
#include "event.h"
|
||||||
|
|
||||||
class notGate : public gate {
|
class notGate : public gate {
|
||||||
|
public:
|
||||||
notGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2);
|
notGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2);
|
||||||
void evaluate(int evTime);
|
void evaluate(int evTime);
|
||||||
};
|
};
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "wire.h"
|
#include "wire.h"
|
||||||
|
|
||||||
class orGate : public gate {
|
class orGate : public gate {
|
||||||
|
public:
|
||||||
orGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
orGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||||
wire* wire3);
|
wire* wire3);
|
||||||
void evaluate(int evTime);
|
void evaluate(int evTime);
|
||||||
|
@ -1,30 +1,38 @@
|
|||||||
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <queue>
|
||||||
#include "wire.h"
|
#include "wire.h"
|
||||||
#include "pQueue.h"
|
|
||||||
#include "orGate.h"
|
#include "orGate.h"
|
||||||
|
#include "xorGate.h"
|
||||||
|
#include "norGate.h"
|
||||||
|
#include "xnorGate.h"
|
||||||
#include "andGate.h"
|
#include "andGate.h"
|
||||||
|
#include "nandGate.h"
|
||||||
#include "notGate.h"
|
#include "notGate.h"
|
||||||
|
#include "event.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int getDelay(string d);
|
int getDelay(string d);
|
||||||
bool parseCircuit(vector<gate*> &gates, vector<wire*> &wires, fileName);
|
bool parseCircuit(priority_queue<event> e, vector<gate*> &gates,
|
||||||
|
vector<wire*> &wires, string fileName);
|
||||||
wire* findWire(int n, vector<wire*> wires);
|
wire* findWire(int n, vector<wire*> wires);
|
||||||
|
bool parseVector(priority_queue<event> e, string fileName);
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
// 1. Parse circuit file to create in-memory data structure of Gates and Wires
|
// 1. Parse circuit file to create in-memory data structure of Gates and Wires
|
||||||
// to simulate
|
// to simulate
|
||||||
vector<gate*> gates;
|
vector<gate*> gates;
|
||||||
vector<wire*> wires;
|
vector<wire*> wires;
|
||||||
|
priority_queue<event> e;
|
||||||
string fileName;
|
string fileName;
|
||||||
getline(cin, fileName);
|
getline(cin, fileName);
|
||||||
bool parseSuccess = parseCircuit(gates, wires, fileName);
|
bool parseSuccess = parseCircuit(e, gates, wires, fileName);
|
||||||
|
|
||||||
if(parseSuccess) {
|
if(parseSuccess) {
|
||||||
// 2. Parse the vector file to initialize the simulation Queue with initial
|
// 2. Parse the vector file to initialize the simulation Queue with initial
|
||||||
// Wire state (i.e., value) changes
|
// Wire state (i.e., value) changes
|
||||||
priority_queue< e;
|
parseSuccess = parseVector(e, fileName);
|
||||||
parseSuccess = e.parseVector(fileName);
|
|
||||||
|
|
||||||
// 3. Simulate the circuit using Event-driven control
|
// 3. Simulate the circuit using Event-driven control
|
||||||
// first, remove the top Event e in the Queue
|
// first, remove the top Event e in the Queue
|
||||||
@ -33,11 +41,13 @@ int main() {
|
|||||||
// fourth, apply e's effects
|
// fourth, apply e's effects
|
||||||
|
|
||||||
// 4. Print the results of the simulation
|
// 4. Print the results of the simulation
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parseCircuit(vector<gate*> &gates, vector<wire*> &wires, fileName) {
|
bool parseCircuit(priority_queue<event> e, vector<gate*> &gates,
|
||||||
|
vector<wire*> &wires, string fileName) {
|
||||||
ifstream in;
|
ifstream in;
|
||||||
circuit.open(fileName + ".txt");
|
in.open(fileName + ".txt");
|
||||||
if(in.fail()) {
|
if(in.fail()) {
|
||||||
cerr << endl << fileName << ".txt could not be opened :(";
|
cerr << endl << fileName << ".txt could not be opened :(";
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -50,10 +60,10 @@ bool parseCircuit(vector<gate*> &gates, vector<wire*> &wires, fileName) {
|
|||||||
getline(in, tmpString);
|
getline(in, tmpString);
|
||||||
|
|
||||||
while(!in.eof()) {
|
while(!in.eof()) {
|
||||||
tmpType << in;
|
in >> tmpType;
|
||||||
|
|
||||||
tmpString << in;
|
in >> tmpString;
|
||||||
tmp1 << in;
|
in >> tmp1;
|
||||||
if(tmpType == "INPUT") {
|
if(tmpType == "INPUT") {
|
||||||
tmpWire = new wire(tmp1, true, tmpString);
|
tmpWire = new wire(tmp1, true, tmpString);
|
||||||
wires.push_back(tmpWire);
|
wires.push_back(tmpWire);
|
||||||
@ -61,45 +71,45 @@ bool parseCircuit(vector<gate*> &gates, vector<wire*> &wires, fileName) {
|
|||||||
tmpWire = new wire(tmp1, false, tmpString);
|
tmpWire = new wire(tmp1, false, tmpString);
|
||||||
wires.push_back(tmpWire);
|
wires.push_back(tmpWire);
|
||||||
}else if(tmpType == "NOT") {
|
}else if(tmpType == "NOT") {
|
||||||
tmp2 << in;
|
in >> tmp2;
|
||||||
tmpGate = new notGate(getDelay(tmpString), findWire(tmp1),
|
tmpGate = new notGate(&e, getDelay(tmpString), findWire(tmp1, wires),
|
||||||
findWire(tmp2));
|
findWire(tmp2, wires));
|
||||||
gates.push_back(tmpGate);
|
gates.push_back(tmpGate);
|
||||||
}else if(tmpType == "AND") {
|
}else if(tmpType == "AND") {
|
||||||
tmp2 << in;
|
in >> tmp2;
|
||||||
tmp3 << in;
|
in >> tmp3;
|
||||||
tmpGate = new andGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
tmpGate = new andGate(&e, getDelay(tmpString), findWire(tmp1, wires),
|
||||||
findWire(tmp3));
|
findWire(tmp2, wires), findWire(tmp3, wires));
|
||||||
gates.push_back(tmpGate);
|
gates.push_back(tmpGate);
|
||||||
}else if(tmpType == "NAND") {
|
}else if(tmpType == "NAND") {
|
||||||
tmp2 << in;
|
in >> tmp2;
|
||||||
tmp3 << in;
|
in >> tmp3;
|
||||||
tmpGate = new nandGate(getDelay(tmpString), findWire(tmp1),
|
tmpGate = new nandGate(&e, getDelay(tmpString), findWire(tmp1, wires),
|
||||||
findWire(tmp2), findWire(tmp3));
|
findWire(tmp2, wires), findWire(tmp3, wires));
|
||||||
gates.push_back(tmpGate);
|
gates.push_back(tmpGate);
|
||||||
}else if(tmpType == "OR") {
|
}else if(tmpType == "OR") {
|
||||||
tmp2 << in;
|
in >> tmp2;
|
||||||
tmp3 << in;
|
in >> tmp3;
|
||||||
tmpGate = new orGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
tmpGate = new orGate(&e, getDelay(tmpString), findWire(tmp1, wires),
|
||||||
findWire(tmp3));
|
findWire(tmp2, wires), findWire(tmp3, wires));
|
||||||
gates.push_back(tmpGate);
|
gates.push_back(tmpGate);
|
||||||
}else if(tmpType == "XOR") {
|
}else if(tmpType == "XOR") {
|
||||||
tmp2 << in;
|
in >> tmp2;
|
||||||
tmp3 << in;
|
in >> tmp3;
|
||||||
tmpGate = new xorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
tmpGate = new xorGate(&e, getDelay(tmpString), findWire(tmp1, wires),
|
||||||
findWire(tmp3));
|
findWire(tmp2, wires), findWire(tmp3, wires));
|
||||||
gates.push_back(tmpGate);
|
gates.push_back(tmpGate);
|
||||||
}else if(tmpType == "NOR") {
|
}else if(tmpType == "NOR") {
|
||||||
tmp2 << in;
|
in >> tmp2;
|
||||||
tmp3 << in;
|
in >> tmp3;
|
||||||
tmpGate = new norGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
tmpGate = new norGate(&e, getDelay(tmpString), findWire(tmp1, wires),
|
||||||
findWire(tmp3));
|
findWire(tmp2, wires), findWire(tmp3, wires));
|
||||||
gates.push_back(tmpGate);
|
gates.push_back(tmpGate);
|
||||||
}else if(tmpType == "XNOR") {
|
}else if(tmpType == "XNOR") {
|
||||||
tmp2 << in;
|
in >> tmp2;
|
||||||
tmp3 << in;
|
in >> tmp3;
|
||||||
tmpGate = new xnorGate(getDelay(tmpString), findWire(tmp1), findWire(tmp2),
|
tmpGate = new xnorGate(&e, getDelay(tmpString), findWire(tmp1, wires),
|
||||||
findWire(tmp3));
|
findWire(tmp2, wires), findWire(tmp3, wires));
|
||||||
gates.push_back(tmpGate);
|
gates.push_back(tmpGate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -107,7 +117,7 @@ bool parseCircuit(vector<gate*> &gates, vector<wire*> &wires, fileName) {
|
|||||||
|
|
||||||
wire* findWire(int n, vector<wire*> wires) {
|
wire* findWire(int n, vector<wire*> wires) {
|
||||||
for(auto i = wires.begin(); i != wires.end(); ++i) {
|
for(auto i = wires.begin(); i != wires.end(); ++i) {
|
||||||
if(n == *i) return i;
|
if(n == (**i).getNumber()) return *i;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@ -116,3 +126,7 @@ int getDelay(string d) {
|
|||||||
d.resize(d.size() - 2);
|
d.resize(d.size() - 2);
|
||||||
return atoi(d.c_str());
|
return atoi(d.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool parseVector(priority_queue<event> e, string fileName) {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "wire.h"
|
#include "wire.h"
|
||||||
|
|
||||||
class xnorGate : public gate {
|
class xnorGate : public gate {
|
||||||
|
public:
|
||||||
xnorGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
xnorGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||||
wire* wire3);
|
wire* wire3);
|
||||||
void evaluate(int evTime);
|
void evaluate(int evTime);
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "wire.h"
|
#include "wire.h"
|
||||||
|
|
||||||
class xorGate : public gate {
|
class xorGate : public gate {
|
||||||
|
public:
|
||||||
xorGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
xorGate(priority_queue<event> *eQueue, int d, wire* wire1, wire* wire2,
|
||||||
wire* wire3);
|
wire* wire3);
|
||||||
void evaluate(int evTime);
|
void evaluate(int evTime);
|
||||||
|
Loading…
Reference in New Issue
Block a user