-
Notifications
You must be signed in to change notification settings - Fork 1
/
Floor_plan_EDA_project.cpp
166 lines (159 loc) · 5.16 KB
/
Floor_plan_EDA_project.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#include <regex>
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <fstream>
#include <map>
#include <sstream>
#include <stdlib.h>
#include "dataStruct.h"
#include "FloorPlanAlgorithm.h"
using namespace std;
string typeStr[] = { "softrectilinear","hardrectilinear","terminal" };
vector<Block> blocks;
vector<Net> nets;
map<string, int> blocksMap;
void readFromFile() {
ifstream input1, input2, input3;
input1.open("ami33.blocks", ios::out | ios::in);
input2.open("ami33.nets", ios::out | ios::in);
input3.open("ami33.pl", ios::out | ios::in);
string data1, data2, data3;
regex reg1("(.+) (softrectilinear|hardrectilinear|terminal)( \d+){0,1}( \((\\d+)\\, (\\d+)\))*");
regex reg2("(\\()(\\d+)(\\, )(\\d+)(\\))");
regex reg3("\\d+");
smatch m;
int id = 1;
if (input1) {
while (getline(input1, data1)) {
//cout << data1 << endl;
bool found = regex_search(data1, m, reg1);
if (found) {
Block b;
b.idNum = id++;
b.id = m.str(1);
blocksMap[b.id] = b.idNum - 1;
for (int i = 0; i < 3; i++) {
if (typeStr[i].compare(m.str(2)) == 0) {
b.type = blockType(i);
if (b.type == HardBlock)
b.coordNum = 4;
}
}
if (b.type == Terminals) {
b.width = 0;
b.height = 0;
blocks.push_back(b);
continue;
}
string str1(m.suffix().str() + "");
string::const_iterator its = str1.begin();
string::const_iterator ite = str1.end();
int j = 0;
while (regex_search(its, ite, m, reg2)) {
b.coords[j].x = atoi(m.str(2).c_str());
b.coords[j].y = atoi(m.str(4).c_str());
j++;
its = m[0].second;
}
b.width = b.coords[1].y;
b.height = b.coords[2].x;
blocks.push_back(b);
}
}
}
else {
cout << "ami33.blocks not exists!" << endl;
}
for (int i = 0; i < blocks.size(); i++) {
cout << blocks[i].id << " " << blocks[i].idNum<<" "<<blocks[i].type<<" "
<< blocks[i].coordNum;
for (int j = 0; j < 4; j++) {
cout << " (" << blocks[i].coords[j].x << ", " << blocks[i].coords[j].y<<")";
}
cout << endl;
}
regex reg4("(NetDegree : )(\\d+)(\n)(#(.*)\n)?");
regex reg5("(.*)( B)(\t: %)?((-)?\\d+(.)?\\d+)?( %)?((-)?\\d+(.)?\\d+)?");
id = 1;
if (input2) {
//input2 >> data2;
ostringstream buf;
char ch;
while (buf && input2.get(ch)) {
buf.put(ch);
}
data2 = buf.str();
//cout << data2<<endl;
string::const_iterator its = data2.begin();
string::const_iterator ite = data2.end();
while (regex_search(its, ite, m, reg4)) {
//cout << m.str() << " " << m.str(2) << endl;
its = m[0].second;
int j = atoi(m.str(2).c_str());
Net net;
net.id = id++;
net.netDegree = j;
while (regex_search(its, ite, m, reg5) && j > 0) {
/*cout << m.str() <<" " << m.str(1) <<" 4:"
<<m.str(4)<<" 8:"
<< m.str(8)<<" "
<< endl;*/
int pos = blocksMap[m.str(1)];
Block_tmp bt;
bt.idNum = pos + 1;
if (strlen(m.str(4).c_str()) > 0) {
bt.n1 = stod(m.str(4).c_str());
bt.n2 = stod(m.str(8).c_str());
}
net.blocks.push_back(bt);
its = m[0].second;
j--;
}
nets.push_back(net);
}
}
else {
cout << "ami33.nets not exists!" << endl;
}
for (int i = 0; i < nets.size(); i++) {
cout << nets[i].id << " " << nets[i].netDegree;
for (int j = 0; j < nets[i].blocks.size(); j++) {
cout << " ("<<nets[i].blocks[j].idNum << " " << nets[i].blocks[j].n1 << " " << nets[i].blocks[j].n2 << ") ";
}
cout << endl;
}
string bid;
int a, b;
regex reg6("(.+)(\t|\s)(\\d+)(\t|\s)(\\d+)");
if (input3) {
while (getline(input3,data3)) {
bool found = regex_search(data3, m, reg6);
bid = m.str(1);
a = atoi(m.str(3).c_str());
b = atoi(m.str(5).c_str());
blocks[blocksMap[bid]].x = a;
blocks[blocksMap[bid]].y = b;
}
}
else {
cout << "ami33.pl not exists!" << endl;
}
for (int i = 0; i < blocks.size(); i++) {
cout << blocks[i].id << " " << blocks[i].idNum << " " << blocks[i].x << " "
<< blocks[i].y<<endl;
}
input1.close();
input2.close();
input3.close();
}
void run_floor_plan() {
FloorPlan fpl = FloorPlan(blocks,nets,blocksMap);
fpl.run();
}
int main()
{
readFromFile();
run_floor_plan();
}