Permalink
Browse files

Fixed bug in evals

  • Loading branch information...
1 parent 853b795 commit c62059422fc24e4eefa2f6c529c60fce244ff70d @unregistered unregistered committed May 4, 2012
Showing with 50 additions and 40 deletions.
  1. +15 −4 design.cpp
  2. +1 −1 design.h
  3. +28 −27 gate.cpp
  4. +1 −1 gatesim.cpp
  5. +5 −7 logicsim.cpp
View
@@ -281,16 +281,22 @@ void Design::toposort()
// For each node with no outgoing edges
for(it = this->get_po_nets().begin(); it != this->get_po_nets().end(); it++)
{
- ERROR("Consider " << (*it)->name() );
// If N has not been marked as visited
if((*it)->color == WHITE) {
this->DFSvisit(*it);
}
}
}
-Net* Design::DFSvisit(Net* currentNet)
+void tabin(int depth) {
+ for(int i=0; i<depth; i++) {
+ cout << "\t";
+ }
+}
+Net* Design::DFSvisit(Net* currentNet, int depth)
{
+ cout << endl;
+ tabin(depth);
cout << "Visiting " << currentNet->name() << ", which depends on: ";
currentNet->color = GREY;
// For each driver
@@ -300,15 +306,20 @@ Net* Design::DFSvisit(Net* currentNet)
// And each driver's nets
for(vector<Net *>:: iterator net = (*gate)->getInputs()->begin(); net != (*gate)->getInputs()->end(); net++)
{
- cout << "Net: " << (*net)->name() << " color " << (*net)->color << endl;
+ tabin(depth);
+ cout << "Net: " << (*net)->name() << " color " << (*net)->color;
if((*net)->color == WHITE) {
- this->DFSvisit(*net);
+ this->DFSvisit(*net, depth+1);
}
else if((*net)->color == GREY) {
(*net)->color = BLACK;
}
}
}
+
+ if(currentNet->getDrivers()->size() == 0)
+ cout << endl;
+
toposortedList.push_back(currentNet );
return currentNet;
}
View
@@ -39,7 +39,7 @@ class Design {
vector<Net *> all_nets();
vector<Gate *> all_gates();
void dump(ostream &os);
- Net* DFSvisit(Net* currentNet);
+ Net* DFSvisit(Net* currentNet, int depth = 0);
void toposort();
deque<Net *> get_toposortedList();
map<string, Net*>* get_design_nets() { return &design_nets; }
View
@@ -1,6 +1,7 @@
#include "gate.h"
using namespace std;
+
//===================================================================//
// GATES CLASS
//
@@ -295,12 +296,12 @@ char Nor::eval()
}
case '0':
{
- val = '1';
+ val = inputs->front()->getVal();
break;
}
case '1':
{
- val = '0';
+ val = inputs->front()->getVal();
break;
}
}
@@ -319,7 +320,7 @@ char Nor::eval()
val = 'X';
}
else if(val == '1') {
- val = '0';
+ val = '1';
}
else {
//error in val
@@ -328,20 +329,12 @@ char Nor::eval()
}
case '0':
{
- if (val == 'X') {
- // do nothing
- }
- else if(val == '0') {
- val = '1';
- }
- else if(val == '1') {
- val = '0';
- }
+ // nothing needed to do
break;
}
case '1':
{
- val = '0';
+ val = '1';
break;
}
default:
@@ -353,6 +346,15 @@ char Nor::eval()
}
}
return val;
+
+ // Now invert
+ if(val == '1')
+ return '0';
+ else if(val == '0')
+ return '1';
+ else
+ return val;
+
}
void Nor::dump(ostream &os)
@@ -398,12 +400,12 @@ char Nand::eval()
}
case '0':
{
- val = '1';
+ val = inputs->front()->getVal();
break;
}
case '1':
{
- val = '0';
+ val = inputs->front()->getVal();
break;
}
}
@@ -422,7 +424,7 @@ char Nand::eval()
val = 'X';
}
else if(val == '0') {
- val = '1';
+ val = '0';
}
else {
//error in val
@@ -431,20 +433,12 @@ char Nand::eval()
}
case '0':
{
- val = '1';
+ val = '0';
break;
}
case '1':
{
- if (val == 'X') {
- // do nothing
- }
- else if(val == '0') {
- val = '1';
- }
- else if(val == '1') {
- val = '0';
- }
+ // nothing needed to do
break;
}
default:
@@ -455,7 +449,14 @@ char Nand::eval()
}
}
}
- return val;
+
+ // Now invert
+ if(val == '1')
+ return '0';
+ else if(val == '0')
+ return '1';
+ else
+ return val;
}
void Nand::dump(ostream &os)
View
@@ -29,7 +29,7 @@ int main (int argc, char const *argv[])
deque<Net *> list = a->get_toposortedList();
LogicSim sim(sfile);
sim.runSimulation(list);
- sim.outputTheFile(ofile);
+ sim.outputTheFile(ofile, a);
} catch(runtime_error &ex) {
stringstream ss;
ss << "Reason: " << ex.what();
View
@@ -126,20 +126,18 @@ void LogicSim::outputTheFile(string file, Design* design)
outfile << endl;
// For each line
+ int index = 0;
for(vector<map<string,char> >::iterator it=values.begin(); it!=values.end(); it++){
map<string,char> value = *it;
for(vector<string>::iterator jt=pi_order.begin(); jt!=pi_order.end(); jt++) {
outfile << value[*jt] << " ";
}
outfile << "=> ";
- int maxDelay = 0;
for(vector<Net*>::iterator jt=design->get_po_nets().begin(); jt!=design->get_po_nets().end(); jt++) {
- outfile << (*jt)->getVal();
- if(jt+1 != design->get_po_nets().end())
- outfile << " ";
- maxDelay = max(maxDelay, (*jt)->computeDelay());
- }
- outfile << "@" << maxDelay << endl;
+ outfile << results.at(index)[(*jt)->name()] << "@" << (*jt)->computeDelay() << " ";
+ }
+ index++;
+ outfile << endl;
}

0 comments on commit c620594

Please sign in to comment.