-
Notifications
You must be signed in to change notification settings - Fork 0
/
lefParser.h
209 lines (198 loc) · 5.99 KB
/
lefParser.h
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
#pragma once
#include "lefStru.h"
#include "help.h"
class lefParser
{
private:
int dbu=2000;
qstringList codeList;
int getPin(int i, LEF::cell &c)
{
LEF::pin p;
//get pinName
p.name=help::getLastElm(this->codeList[i],"PIN");
i++;
//实际读内容
for(int j=i;j<this->codeList.size();j++)
{
qstring stri=this->codeList[j];
if(stri.find("LAYER"))
{
qstring layer=help::getLastElm(stri,"LAYER");
int m=qstring(layer[layer.size()-1]).toInt();
p.metal=this->getMetal(m);
}
else if(stri.find("RECT "))
{
rect r=rect::getRect(stri,c.sizeA1,c.sizeA2);
r.plusDbu(dbu);
p.allRect.push_back(pinRect(r));
}
else if(stri.find("END "+p.name))
{
c.allPin.push_back(p);
return j;
}
}
return -1;
}
int getOBS(int i, LEF::cell &c)
{
qstring layerName;
for(int j=i;i<this->codeList.size();j++)
{
qstring stri=this->codeList[j];
if(stri.find("LAYER"))
layerName=help::getLastElm(stri,"LAYER");
else
{
if(layerName!="")
{
if(stri.find("RECT"))
{
rect r=rect::getRect(stri,c.sizeA1,c.sizeA2);
r.plusDbu(dbu);
c.o[layerName].push_back(r);
}
}
if(stri.find("END"))
return j;
}
}
return -1;
}
LEF::metal _getMetal(int _m)
{
qstring metalName="METAL"+qstring::number(_m);
LEF::metal m;
bool findMet=false;
for(int i=0;i<codeList.size();i++)
{
qstring stri=codeList[i];
if(findMet==false && stri=="LAYER "+metalName) //找到metal位置,进状态
{
m.ID=_m;
findMet=true;
}
else if(findMet)
{
if(stri.find("SPACING"))
{
m.spacing=help::getLastElm(stri,"SPACING").toFloat();
m.spacing*=dbu;
}
else if(stri.find("MINWIDTH"))
continue;
else if(stri.find("WIDTH"))
{
m.minWidth=help::getLastElm(stri,"WIDTH").toFloat();
m.minWidth*=dbu;
}
else if(stri.find("AREA"))
{
m.area=help::getLastElm(stri,"AREA").toFloat();
m.area*=dbu;
}
else if(stri.find("DIRECTION"))
{
if(stri.find("VERTICAL"))
m.vertical=true;
else
m.vertical=false;
}
else if(stri=="END "+metalName)
break;
}
}
return m;
}
const int minMetalID;
public:
vector<LEF::metal> allMetal;
lefParser(qstring code, int minMetalID, int maxMetalID) : minMetalID(minMetalID)
{
codeList=code.split("\n");
for(int i=minMetalID;i<=maxMetalID;i++)
this->allMetal.push_back(this->_getMetal(i));
}
LEF::metal getMetal(int ID)
{
return this->allMetal[ID-minMetalID];
}
LEF::via getVia(int m1)
{
qstring viaName="via"+qstring::number(m1);
qstring m1Name="METAL"+qstring::number(m1);
qstring m2Name="METAL"+qstring::number(m1+1);
LEF::via v;
bool findVia=false;
for(int i=0;i<codeList.size();i++)
{
qstring stri=codeList[i];
if(findVia==false && stri=="VIA "+viaName+" DEFAULT") //找到via位置,进状态
{
v.m1=m1;
findVia=true;
}
else if(findVia)
{
if(stri.find("LAYER VIA"+qstring::number(m1)))
{
v.viaRect=rect::getRect(codeList[i+1],-1,-1,true);
v.viaRect.plusDbu(dbu);
}
else if(stri.find("LAYER "+m1Name))
{
v.m1Rect=rect::getRect(codeList[i+1],-1,-1,true);
v.m1Rect.plusDbu(dbu);
}
else if(stri.find("LAYER "+m2Name))
{
v.m2Rect=rect::getRect(codeList[i+1],-1,-1,true);
v.m2Rect.plusDbu(dbu);
}
else if(stri.find("END "+viaName))
break;
}
}
return v;
}
LEF::cell getCell(qstring cellName)
{
LEF::cell c;
bool findCell=false;
for(int i=0;i<codeList.size();i++)
{
qstring stri=codeList[i];
if(findCell==false && stri=="MACRO "+cellName) //找到CELL位置,进状态
{
c.cellName=cellName;
findCell=true;
}
else if(findCell)
{
if(stri.find("SIZE"))
{
qstringList sizeList=help::splitSpace(stri);
for(int j=0;j<sizeList.size();j++)
{
if(sizeList[j]=="SIZE")
{
c.sizeA1=sizeList[j+1].toFloat();
c.sizeA2=sizeList[j+3].toFloat();
break;
}
}
}
else if(stri.find("PIN"))
i=this->getPin(i,c);
else if(stri.find("OBS"))
i=this->getOBS(i+1,c);
else if(stri.find("END "+cellName))
break;
}
}
c.plusDbu(dbu);
return c;
}
};