-
Notifications
You must be signed in to change notification settings - Fork 0
/
defParser.h
102 lines (95 loc) · 2.64 KB
/
defParser.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
#pragma once
#include "defStru.h"
class defParser
{
private:
int parseComponents(int i)
{
for(int j=i;j<this->codeList.size();j++)
{
qstring stri=this->codeList[j];
if(stri.find("inst"))
this->allComponent.push_back(DEF::component::get(stri));
else if(stri=="END COMPONENTS")
return j;
}
return -1;
}
int parsePins(int i) //fix:现在没有做向外部pin连线的
{
for(int j=i;j<this->codeList.size();j++)
{
qstring stri=this->codeList[j];
if(stri=="END PINS")
return j;
}
}
int getPin(int i, DEF::net &n)
{
for(int j=i;j<this->codeList.size();j++)
{
qstring stri=this->codeList[j];
if(stri.find(";"))
return j;
else
{
qstringList strList=help::splitSpace(stri);
for(int i=0;i<strList.size();i++)
{
if(strList[i]=="(")
{
DEF::pin p;
p.instName=strList[i+1];
if(p.instName!="PIN")
{
p.pinName=strList[i+2];
n.allPin.push_back(p);
}
}
}
}
}
return -1;
}
int parseNets(int i)
{
auto getNetName=[](qstring stri) {
stri=stri.replace(" ","");
return stri.mid(1); //截掉-
};
for(int j=i;j<this->codeList.size();j++)
{
qstring stri=this->codeList[j];
if(stri.find("net"))
{
DEF::net n(getNetName(stri));
j=this->getPin(j,n);
this->allNet.push_back(n);
}
else if(stri=="END NETS")
return j;
}
return -1;
}
public:
vector<DEF::component> allComponent;
vector<DEF::pin> allPin; //接口
vector<DEF::net> allNet; //导线连接
qstringList codeList;
defParser(qstring code)
{
this->codeList=code.split("\n");
for(int i=0;i<this->codeList.size();i++)
{
qstring stri=this->codeList[i];
if(stri.find("COMPONENTS"))
i=this->parseComponents(i+1);
/*else if(stri.find("PINS")) //暂不考虑
i=this->parsePins(i+1);*/
else if(stri.find("NETS"))
i=this->parseNets(i+1);
else if(stri=="END DESIGN")
break;
}
}
};