forked from rmanohar/layout
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cc
296 lines (251 loc) · 7.45 KB
/
main.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
289
290
291
292
293
294
295
296
/*************************************************************************
*
* Copyright (c) 2019 Rajit Manohar
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
**************************************************************************
*/
#include <stdio.h>
#include <common/list.h>
#include <unistd.h>
#include <math.h>
#include <string.h>
#include <map>
#include <act/passes.h>
#include <act/iter.h>
#include "stk_layout.h"
#include "geom.h"
void usage (char *name)
{
fprintf (stderr, "Unknown options.\n");
fprintf (stderr, "Usage: %s -p procname [-s] [-o <name>] [-a <mult>] [-c <cell>] <file.act>\n", name);
fprintf (stderr, " -p procname: name of ACT process corresponding to the top-level of the design\n");
fprintf (stderr, " -o <name>: output files will be <name>.<extension> (default: out)\n");
fprintf (stderr, " -s : emit spice netlist\n");
fprintf (stderr, " -P : include PINS section in DEF file\n");
fprintf (stderr, " -a <mult>: use <mult> as the area multiplier for the DEF fie (default 1.4)\n");
fprintf (stderr, " -r <ratio> : use this as the aspect ratio = x-size/y-size (default 1.0)\n");
fprintf (stderr, " -c <cell>: Read in the <cell> ACT file as a starting point for cells,\n\toverwriting it with an updated version with any new cells\n");
fprintf (stderr, " -S : share staticizers\n");
//fprintf (stderr, " -A : report area\n");
fprintf (stderr, " -R : generate report\n");
fprintf (stderr, "\n");
exit (1);
}
int main (int argc, char **argv)
{
Act *a;
Process *p;
int ch;
char *proc_name = NULL;
char *outname = NULL;
char *cellname = NULL;
int do_pins = 0;
int do_spice = 0;
char buf[1024];
FILE *fp;
double area_multiplier;
double aspect_ratio;
int report = 0;
int share_staticizers = 0;
area_multiplier = 1.4;
aspect_ratio = 1.0;
Act::Init (&argc, &argv, "layout:layout.conf");
{
char *tmpfile = config_file_name ("macros.conf");
if (tmpfile) {
FREE (tmpfile);
config_read ("macros.conf");
}
}
#if 0
if (Technology::T->nmetals < 2) {
fatal_error ("Can't handle a process with fewer than two metal layers!");
}
#endif
while ((ch = getopt (argc, argv, "c:p:o:sSPRa:r:")) != -1) {
switch (ch) {
case 'S':
share_staticizers = 1;
break;
case 'R':
report = 1;
break;
case 'a':
area_multiplier = atof (optarg);
break;
case 'r':
aspect_ratio = atof (optarg);
break;
case 'c':
if (cellname) {
FREE (cellname);
}
cellname = Strdup (optarg);
break;
case 'P':
do_pins = 1;
break;
case 'p':
if (proc_name) {
FREE (proc_name);
}
proc_name = Strdup (optarg);
break;
case 'o':
if (outname) {
FREE (outname);
}
outname = Strdup (optarg);
break;
case 's':
do_spice = 1;
break;
case '?':
fprintf (stderr, "Unknown option.\n");
usage (argv[0]);
break;
default:
fatal_error ("shouldn't be here");
break;
}
}
if (optind != argc - 1) {
fprintf (stderr, "Missing act file name.\n");
usage (argv[0]);
}
if (!proc_name) {
fatal_error ("Missing process name!");
}
if (!outname) {
outname = Strdup ("out");
}
/*--- read in and expand ACT file ---*/
a = new Act (argv[optind]);
/* merge in cell file name, if it exists */
if (cellname) {
FILE *cf = fopen (cellname, "r");
if (cf) {
fclose (cf);
a->Merge (cellname);
}
}
a->Expand();
/*--- find top level process ---*/
p = a->findProcess (proc_name);
if (!p) {
fatal_error ("Could not find process `%s' in act file `%s'.\n",
proc_name, argv[optind]);
}
/*--- core passes ---*/
ActCellPass *cp = new ActCellPass (a);
cp->run (p);
ActDynamicPass *lp = new ActDynamicPass(a, "stk2layout", "pass_layout.so", "layout");
ActNetlistPass *netinfo;
netinfo = dynamic_cast<ActNetlistPass *>(a->pass_find ("prs2net"));
if (share_staticizers) {
netinfo->enableSharedStat();
}
netinfo->run (p);
/* --- emit SPICE netlist, if requested --- */
if (do_spice) {
snprintf (buf, 1024, "%s.sp", outname);
FILE *sp = fopen (buf, "w");
if (!sp) { fatal_error ("Could not open file `%s'", buf); }
netinfo->Print (sp, p);
fclose (sp);
}
lp->run (p);
ActNamespace *cell_ns = a->findNamespace ("cell");
Assert (cell_ns, "No cell namespace? No circuits?!");
//a->Print (stdout);
/*--- print out lef file, plus rectangles ---*/
snprintf (buf, 1024, "%s.lef", outname);
fp = fopen (buf, "w");
if (!fp) {
fatal_error ("Could not open file `%s' for writing", buf);
}
lp->setParam ("lef_file", (void *)fp);
FILE *fpcell;
snprintf (buf, 1024, "%s.cell", outname);
fpcell = fopen (buf, "w");
if (!fpcell) {
fatal_error ("Could not open file `%s' for writing", buf);
}
lp->setParam ("cell_file", (void *)fpcell);
/* emit lef and cell files */
lp->run_recursive (p, 1);
fclose (fp);
fclose (fpcell);
lp->setParam ("cell_file", (void*)NULL);
lp->setParam ("lef_file", (void*)NULL);
/* emit rect */
lp->run_recursive (p, 4);
/*
preparation for DEF file generation: create flat netlist using
special method in the booleanize pass
*/
ActBooleanizePass *boolinfo;
boolinfo = dynamic_cast<ActBooleanizePass *> (a->pass_find ("booleanize"));
boolinfo->createNets (p);
/* --- print out def file --- */
snprintf (buf, 1024, "%s.def", outname);
fp = fopen (buf, "w+");
if (!fp) {
fatal_error ("Could not open file `%s' for writing", buf);
}
lp->setParam ("def_file", (void *)fp);
lp->setParam ("do_pins", do_pins);
lp->setParam ("area_mult", area_multiplier);
lp->setParam ("aspect_ratio", aspect_ratio);
lp->run_recursive (p, 5);
fclose (fp);
lp->setParam ("def_file", (void*)NULL);
if (report) {
double a = lp->getRealParam ("total_area");
double as = lp->getRealParam ("stdcell_area");
a *= Technology::T->scale/1000.0;
a *= Technology::T->scale/1000.0;
as *= Technology::T->scale/1000.0;
as *= Technology::T->scale/1000.0;
if (a > 1e4) {
a /= 1e6;
as /= 1e6;
printf ("Total Area: %.3g mm^2\n", a);
printf ("Total StdCell Area: %.3g mm^2 ", as);
}
else {
printf ("Total Area: %.3g um^2\n", a);
printf ("Total StdCell Area: %.3g um^2 ", as);
}
int stdcellht = lp->getIntParam ("cell_maxheight");
printf (" (%.2g%%) [height=%d, #tracks=%d]\n",
(as-a)/a*100.0, stdcellht,
stdcellht/Technology::T->metal[0]->getPitch());
lp->run_recursive (p, 2);
}
/* -- dump updated cells file, if necessary -- */
if (cellname) {
fp = fopen (cellname, "w");
if (!fp) {
fatal_error ("Could not write `%s'", cellname);
}
cp->Print (fp);
fclose (fp);
}
return 0;
}