Skip to content

Commit a273556

Browse files
author
xinoip
committed
find arrival times for every element
1 parent ff9b253 commit a273556

File tree

4 files changed

+35
-24
lines changed

4 files changed

+35
-24
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"thread": "cpp",
6565
"cinttypes": "cpp",
6666
"typeinfo": "cpp",
67-
"variant": "cpp"
67+
"variant": "cpp",
68+
"qstyleoptiongraphicsitem": "cpp"
6869
}
6970
}

circuitelement.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "circuitelement.h"
22
#include <QPainter>
33
#include <QStyleOptionGraphicsItem>
4+
#include "delay_file.h"
45

56
CircuitElement::CircuitElement(){
67
elementName = "";
@@ -9,10 +10,11 @@ CircuitElement::CircuitElement(){
910
}
1011
CircuitElement::CircuitElement(std::string name, CircuitElementType type, std::string subcircuitType)
1112
{
13+
DelayFile delay_file{"/home/pio/repo/plode-pio/foo.txt"};
1214
elementName = name;
1315
elementType = type;
1416
this->subcircuitType = subcircuitType;
15-
delay = 0;
17+
delay = delay_file.delay_of_element(name);
1618
arrivalTime = 0;
1719
}
1820
bool CircuitElement::operator==(const CircuitElement& other)

currentcircuit.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ void topological_sort_helper(std::string element_name, bool visited[], std::stac
4848

4949
void CurrentCircuit::topological_sort() {
5050
Circuit& circ = CurrentCircuit::circ;
51+
auto& adj = circ.adjacencyList;
5152
std::stack<int> stack;
5253
int vertex_count = circ.elements.size();
5354
bool* visited = new bool[vertex_count];
@@ -61,7 +62,34 @@ void CurrentCircuit::topological_sort() {
6162
while (stack.empty() == false) {
6263
int vertex = stack.top();
6364
auto& element = circ.elements[vertex];
64-
printf("%s(d:%d)(a:%d) ", element.elementName.c_str(), element.delay, element.arrivalTime);
65+
std::vector<CircuitElement> predecessor_elements;
66+
67+
for(auto& pair : adj) {
68+
auto& second = pair.second;
69+
for(auto& connection : second) {
70+
if(connection.elementName == element.elementName) {
71+
predecessor_elements.push_back(pair.first);
72+
}
73+
}
74+
}
75+
76+
int max_arrival = 0;
77+
for(auto& predecessor : predecessor_elements) {
78+
int arrival_time = 0;
79+
for(int i = 0; i < circ.elements.size(); i++) {
80+
if(circ.elements[i].elementName == predecessor.elementName) {
81+
arrival_time = circ.elements[i].arrivalTime;
82+
break;
83+
}
84+
}
85+
if(arrival_time > max_arrival) {
86+
max_arrival = arrival_time;
87+
}
88+
}
89+
90+
element.arrivalTime += max_arrival + element.delay;
91+
92+
printf("%s(d:%d)(a:%d)\n", element.elementName.c_str(), element.delay, element.arrivalTime);
6593
stack.pop();
6694
}
6795
printf("\n");

mainwindow.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "mainwindow.h"
2+
#include "delay_file.h"
23

34
MainWindow::MainWindow(QWidget *parent)
45
: QMainWindow(parent)
@@ -69,27 +70,6 @@ void MainWindow::on_convertButton_clicked()
6970
std::cout << "FILE NAME:" << ui->textEdit->toPlainText().toUtf8().constData() << std::endl;
7071
CurrentCircuit::circ.fillFromVerilogFile(ui->textEdit->toPlainText().toUtf8().constData());
7172

72-
std::ifstream inFile;
73-
std::string fileName{"/home/pio/repo/plode-pio/foo.txt"};
74-
inFile.open(fileName);
75-
if (!inFile) {
76-
std::cerr << "Unable to open file foo.txt"<<std::endl;
77-
return;
78-
}
79-
80-
std::string line;
81-
std::vector<std::string> fileLines = Utils::getLinesFromDelayFile(fileName);
82-
for (auto line : fileLines) {
83-
std::vector<std::string> split = Utils::splitStringByDelimiter(line, ' ');
84-
std::string& name = split[0];
85-
int delay = std::stoi(split[1]);
86-
for(int i = 0; i < CurrentCircuit::circ.elements.size(); i++) {
87-
if(CurrentCircuit::circ.elements[i].elementName == name) {
88-
CurrentCircuit::circ.elements[i].delay = delay;
89-
}
90-
}
91-
}
92-
9373
CurrentCircuit::topological_sort();
9474

9575
return;

0 commit comments

Comments
 (0)