made formating better
This commit is contained in:
parent
4f3f006d0d
commit
ed164155f8
@ -1,6 +1,7 @@
|
|||||||
#include "Simulation.h"
|
#include "Simulation.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
bool Simulation::parseCircuit(string fileName)
|
bool Simulation::parseCircuit(string fileName)
|
||||||
{
|
{
|
||||||
@ -138,7 +139,7 @@ bool Simulation::parseVector(string fileName) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simulation::simulate() {
|
void Simulation::simulate(int simTime) {
|
||||||
// loop through event queue
|
// loop through event queue
|
||||||
while(!e.empty()) {
|
while(!e.empty()) {
|
||||||
bool changed;
|
bool changed;
|
||||||
@ -151,7 +152,7 @@ void Simulation::simulate() {
|
|||||||
output->setValue(tmpEvent.getValue(), tmpEvent.getTime());
|
output->setValue(tmpEvent.getValue(), tmpEvent.getTime());
|
||||||
|
|
||||||
// if the wire value changes, evaluate gates
|
// if the wire value changes, evaluate gates
|
||||||
if(changed && !(tmpEvent.getTime() > 60)) {
|
if(changed && !(tmpEvent.getTime() > simTime)) {
|
||||||
Gate * tmpGate;
|
Gate * tmpGate;
|
||||||
Event gateEvent(-1, -1, nullptr);
|
Event gateEvent(-1, -1, nullptr);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@ -170,7 +171,7 @@ void Simulation::simulate() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Simulation::print()
|
void Simulation::print(int simTime)
|
||||||
{
|
{
|
||||||
int lastTime = 0;
|
int lastTime = 0;
|
||||||
int tmpTime = 0;
|
int tmpTime = 0;
|
||||||
@ -181,18 +182,22 @@ void Simulation::print()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
cout << "\n\nWire Traces: \n";
|
||||||
// now iterate through wires, printing each of them
|
// now iterate through wires, printing each of them
|
||||||
for(auto i = wires.begin(); i != wires.end(); ++i) {
|
for(auto i = wires.begin(); i != wires.end(); ++i) {
|
||||||
(**i).setLast(lastTime);
|
(**i).setLast(lastTime);
|
||||||
|
(**i).setPrintLen(simTime);
|
||||||
cout << **i;
|
cout << **i;
|
||||||
}
|
}
|
||||||
|
|
||||||
int t = 0;
|
int t = 0;
|
||||||
cout << setw(10) << "TIME ";
|
cout << setw(6) << "TIME: ";
|
||||||
while(t <= 60 && t <= lastTime) {
|
while(t < simTime && t <= lastTime) {
|
||||||
cout << setw(5) << left << t;
|
cout << setfill('.') << setw(5) << left << t;
|
||||||
t += 5;
|
t += 5;
|
||||||
}
|
}
|
||||||
|
cout << t << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
Wire * Simulation::findWire(int n)
|
Wire * Simulation::findWire(int n)
|
||||||
|
@ -22,8 +22,8 @@ class Simulation {
|
|||||||
public:
|
public:
|
||||||
bool parseCircuit(string fileName);
|
bool parseCircuit(string fileName);
|
||||||
bool parseVector(string fileName);
|
bool parseVector(string fileName);
|
||||||
void simulate();
|
void simulate(int);
|
||||||
void print();
|
void print(int);
|
||||||
private:
|
private:
|
||||||
Wire* findWire(int n);
|
Wire* findWire(int n);
|
||||||
int getDelay(string d);
|
int getDelay(string d);
|
||||||
|
13
src/Wire.cpp
13
src/Wire.cpp
@ -60,7 +60,7 @@ void Wire::convertToIO(string newName)
|
|||||||
isPrint = true;
|
isPrint = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Gate * Wire::getGate(int index)
|
Gate * Wire::getGate(int index) const
|
||||||
{
|
{
|
||||||
if (index < gates.size()) {
|
if (index < gates.size()) {
|
||||||
return gates[index];
|
return gates[index];
|
||||||
@ -73,6 +73,11 @@ void Wire::setLast(int last)
|
|||||||
lastEvent = last;
|
lastEvent = last;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Wire::setPrintLen(int len)
|
||||||
|
{
|
||||||
|
printLen = len;
|
||||||
|
}
|
||||||
|
|
||||||
int Wire::getNumber() const
|
int Wire::getNumber() const
|
||||||
{
|
{
|
||||||
return WireNumber;
|
return WireNumber;
|
||||||
@ -97,12 +102,12 @@ ostream & operator<<(ostream & out, const Wire & c)
|
|||||||
{
|
{
|
||||||
if (c.isPrint) {
|
if (c.isPrint) {
|
||||||
int len = 0;
|
int len = 0;
|
||||||
out << setw(10) << c.name + " ";
|
out << setw(6) << c.name + ": ";
|
||||||
while (len <= 60 && len <= c.lastEvent)
|
while (len <= c.printLen && len <= c.lastEvent)
|
||||||
{
|
{
|
||||||
out << setw(0) << c.getChar(len++);
|
out << setw(0) << c.getChar(len++);
|
||||||
}
|
}
|
||||||
out << endl;
|
out << endl << endl;
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -25,13 +25,14 @@ class Wire {
|
|||||||
void setValue(int newValue, int setTime);
|
void setValue(int newValue, int setTime);
|
||||||
bool doesChange(int newValue, int setTime);
|
bool doesChange(int newValue, int setTime);
|
||||||
void convertToIO(string newName);
|
void convertToIO(string newName);
|
||||||
Gate* getGate(int index);
|
Gate* getGate(int index) const;
|
||||||
void setLast(int last);
|
void setLast(int last);
|
||||||
|
void setPrintLen(int);
|
||||||
|
|
||||||
friend ostream& operator<<(ostream &out, const Wire &c);
|
friend ostream& operator<<(ostream &out, const Wire &c);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int WireNumber, value, lastEvent;
|
int WireNumber, value, lastEvent, printLen;
|
||||||
vector<int> historyTimes;
|
vector<int> historyTimes;
|
||||||
vector<int> historyValues;
|
vector<int> historyValues;
|
||||||
string name;
|
string name;
|
||||||
|
@ -7,9 +7,17 @@ int main() {
|
|||||||
// to simulate
|
// to simulate
|
||||||
string fileName;
|
string fileName;
|
||||||
Simulation e;
|
Simulation e;
|
||||||
|
int len = 60;
|
||||||
|
|
||||||
cout << "Please enter filename: ";
|
cout << "Please enter filename: ";
|
||||||
getline(cin, fileName);
|
getline(cin, fileName);
|
||||||
|
cout << "How long do you want to simulate to (default 60)? ";
|
||||||
|
if (cin.peek() == '\n') {
|
||||||
|
len = 60;
|
||||||
|
}
|
||||||
|
else if (!(cin >> len)) {
|
||||||
|
cout << "Invalid input using 60.\n";
|
||||||
|
}
|
||||||
e.parseCircuit(fileName);
|
e.parseCircuit(fileName);
|
||||||
|
|
||||||
// 2. Parse the vector file to initialize the simulation Queue with initial
|
// 2. Parse the vector file to initialize the simulation Queue with initial
|
||||||
@ -21,8 +29,9 @@ int main() {
|
|||||||
// second, determine if e causes a future Wire state change
|
// second, determine if e causes a future Wire state change
|
||||||
// third, create and queue any future Wire state changes as new Events
|
// third, create and queue any future Wire state changes as new Events
|
||||||
// fourth, apply e's effects
|
// fourth, apply e's effects
|
||||||
e.simulate();
|
e.simulate(len);
|
||||||
|
|
||||||
// 4. Print the results of the simulation
|
// 4. Print the results of the simulation
|
||||||
e.print();
|
e.print(len);
|
||||||
|
system("pause");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user