-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathICCAD.cc
288 lines (263 loc) · 6.34 KB
/
ICCAD.cc
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "DummyInsert.h"
double window_width;
double min_width[20];
double min_space[20];
double max_fill_width[20];
double min_density[20];
double max_density[20];
int total_layer;
//#define runall
/*
void printTest(char *a)
{
printf("%s ", a);
//cout << a << " ";
}*/
#if 0
class file
{
public:
ifstream fp;
getline(char * c, int i)
{
if(fp.getline(c, i))
{
return 1;
}
else
{
return 0;
}
}
file(const char *filename)
{
fp.open(filename);
}
~file()
{
fp.close();
}
};
#endif
void process(char filename[]);
void Insertion_sort(int id, critical_net *&critical_net_head_p);
int main(int argc, char **argv)
{
/*
char a[100];
printf("Input the filename(ex: circuit1.conf, circuit2.config...)\n");
scanf("%s", &a);
printf("%s", a);
process(a);
*/
#ifndef runall
if(argc==2)
process(argv[1]);
else
printf("USAGE: ./cada025 <config filename>\ne.g. ./cada025 circuit1.conf\n");
#else
printf("Warning!!! Run all mode");
for(int i=0; i<50; i++)
printf("!");
printf("\n");
process("circuit1.conf");
process("circuit2.config");
process("circuit3.config");
process("circuit4.config");
process("circuit5.config");
#endif
return 0;
}
void process(char filename[])
{
total_layer = 0;
FILE *fp=fopen(filename, "r");
//file fp("input.conf");
//ifstream designFile, outputFile, rule_fileFile, process_fileFile;
FILE *ruleFile, *processFile;
char line[10000];
char design[20];
char *critical;
char output[20], rule_file[20], process_file[20];
critical_net *critical_net_head = NULL;
if(fp==NULL)
{
fprintf(stderr, "Open config file %s failed, please ensure that the file exist.\n", filename);
exit(EXIT_FAILURE);
}
while(/*fp.getline(line, 999)*/fgets(line, sizeof(line), fp))
{
if(line[0]==';'||line[0]==' ')
{
continue;
}
strtok(line, ":");
switch(line[0])
{
case 'd':
//strcpy(design, strtok(NULL, ": "));
//character = strtok(NULL, ": ");
//printf("%s", strtok(NULL, ": "));
//cout <<strtok(NULL, ": ");
//strtok(NULL, "<");
//strtok(NULL, "\n")+1;
strcpy(design, strtok(NULL, "\n")+1);
//printf("%s", strtok(NULL, "\n")+1);//Windows only
//designFile=fopen(strtok(NULL, "\r")+1, "r");
//designFile.open(strtok(NULL, ">"));
break;
case 'o':
//strtok(NULL, "<");
//strcpy(output, strtok(NULL, ": "));
//strtok(NULL, ">");
//printf("%s", strtok(NULL, "\n")+1);
strcpy(output, strtok(NULL, "\n")+1);
//outputFile.open(strtok(NULL, ">"));
break;
case 'r':
//strtok(NULL, "<");
//strcpy(rule_file, strtok(NULL, ": "));
strcpy(rule_file, strtok(NULL, "\n")+1);
ruleFile=fopen(rule_file, "r");
if(ruleFile==NULL)
{
fprintf(stderr, "Open rule file %s failed, please ensure that the file exist.\n", rule_file);
exit(EXIT_FAILURE);
}
//strtok(NULL, ">");
//rule_fileFile.open(strtok(NULL, ">"));
break;
case 'p':
//strcpy(process_file, strtok(NULL, ": "));
if( line[1]=='r')
{
//strtok(NULL, "<");
strcpy(process_file, strtok(NULL, "\n")+1);
processFile=fopen(process_file, "r");
if(processFile==NULL)
{
fprintf(stderr, "Open process file %s failed, please ensure that the file exist.\n", process_file);
exit(EXIT_FAILURE);
}
//strtok(NULL, ">");
//process_fileFile.open(strtok(NULL, ">"));
break;
}
else if( line[1]=='o')
break;
case 'c':
while((critical = strtok(NULL, " \n")) != NULL)
{
Insertion_sort(atoi(critical), critical_net_head);
}
break;
case 'g':
break;
default:
break;
}
}
fclose(fp);
//rtree(design, output);
//printf("%s", design);
//printf("%s\n%s\n%s\n%s", design, output, rule_file, process_file);
//fgets(line, sizeof(line), ruleFile);
while(fgets(line, sizeof(line), ruleFile))
{
if(line[0]==';'||line[0]==' ')
{
continue;
}
if(line[0]=='\n')
{
break;
}
total_layer++;
int index=atoi(strtok(line, " "))-1;
strtok(NULL, " ");//Type
//printf("%s", strtok(NULL, " "));
//printf("%f", atof(strtok(NULL, " ")));
min_width[index]=atof(strtok(NULL, " "));
min_space[index]=atof(strtok(NULL, " "));
max_fill_width[index]=atof(strtok(NULL, " "));
min_density[index]=atof(strtok(NULL, " "));
max_density[index]=atof(strtok(NULL, " "));
}
/*
int i=0;
printf("%f %f %f %f %f\n", min_width[i], min_space[i], max_fill_width[i], min_density[i], max_density[i]);
*/
while(fgets(line, sizeof(line), processFile))
{
//printf("%s", line);
if(line[0]==';'||line[0]==' '||line[0]=='\n')
{
continue;
}
if(line[0]=='w')
{
strtok(line, " ");
window_width=atof(strtok(NULL, "\n"));
break;
}
}
/*
for(int i=0; i<total_layer; i++){
printf("%f %f %f %f %f\n", min_width[i], min_space[i], max_fill_width[i], min_density[i], max_density[i]);
}*/
fclose(ruleFile);
fclose(processFile);
rtree(design, output, critical_net_head);
/*
fgets(line, sizeof(line), designFile);
printf("%s ", line);
*/
//cout << design;
/*
printTest(design);
printTest(output);
printTest(rule_file);
printTest(process_file);
*/
/*
designFile.getline(line, 999);
cout << line << endl;
designFile.close();
outputFile.getline(line, 999);
cout << line << endl;
outputFile.close();
rule_fileFile.getline(line, 999);
cout << line << endl;
rule_fileFile.close();
process_fileFile.getline(line, 999);
cout << line << endl;
process_fileFile.close();
*/
//auto close file?
//p();
}
void Insertion_sort(int id, critical_net *&critical_net_head)//TODO Using global critical_net_head bad design //Check where it's used to debug //Used in DummyInsert.c
{
critical_net *tmp = new critical_net;
tmp->id = id;
tmp->next = NULL;
if(critical_net_head == NULL){
critical_net_head = tmp;
} else if(tmp->id > critical_net_head->id){
tmp->next = critical_net_head;
critical_net_head = tmp;
} else {
critical_net *prev = critical_net_head;
critical_net *current = critical_net_head->next;
while(current != NULL && tmp->id < current->id)
{
prev = current;
current = current->next;
}
prev->next = tmp;
tmp->next = current;
}
}