-
Notifications
You must be signed in to change notification settings - Fork 0
/
codegen.h
124 lines (113 loc) · 3.58 KB
/
codegen.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
#pragma once
#include "router.h"
class codegen
{
private:
//处理一个net,在后面添加line和via。返回处理完的行下标
int genNet(int i,qstring &result,vector<line> &allLine, vector<via> &allVia)
{
result+=this->l.dp.codeList[i]+"\n"; //把net那行加进去
i++;
for(;i<this->l.dp.codeList.size();i++)
{
qstring stri=this->l.dp.codeList[i];
result+=stri+"\n";
//向下探测有没有到结尾
qstring stri2=this->l.dp.codeList[i+1];
if(stri2.find(";")) //fix:目前sample里暂时没有分号非单独一行的
{
//到结尾了
if(!allLine.empty())
{
result+="+ ROUTED ";
bool first=true;
//把allVia加上
for(via v : allVia)
{
if(!first)
result+="NEW ";
else
first=false;
result+=v.m.getName()+" "+v.getPos()+" "+v.getName()+"\n";
}
//把allLine加上
for(line l : allLine)
{
if(!first)
result+="NEW ";
else
first=false;
pos p1,p2;
tie(p1,p2)=l.getMidLine();
result+=l.metal.getName()+" "+p1.toStr()+" "+p2.toStr()+"\n";
}
}
break;
}
}
result+=";\n";
return i+1; //跳过分号那行到下一个net
}
public:
router l;
codegen(router l) : l(l) {}
qstring doGen()
{
qstring result;
for(int i=0;i<this->l.dp.codeList.size();i++)
{
qstring stri=this->l.dp.codeList[i];
if(stri.find("DESIGN "))
result+="DESIGN result ;\n";
else if(stri.find("NETS"))
result+=this->genNETS(i);
else
result+=stri+"\n";
}
return result;
}
/*QString genNONDEFAULTRULES()
{
QString result="NONDEFAULTRULES 1 ;\n";
result+="- DEFAULT_METAL1_580\n";
for(LEF::metal &m : l.lp.allMetal)
{
result+="+ LAYER "+m.getName()+"\n";
result+="WIDTH "+QString::number(int(m.width));
}
result+=";\n";
result+="END NONDEFAULTRULES\n";
return result;
}*/
qstring genNETS(int &i)
{
qstring result;
//使用类似NETparser,每个net结束之后添加对应下标的line
bool findNet=false;
int netNum=0;
for(;i<this->l.dp.codeList.size();i++)
{
qstring stri=this->l.dp.codeList[i];
if(!findNet && stri.find("NETS"))
{
result+=stri+"\n";
findNet=true;
}
if(findNet)
{
if(stri.find("net")) //如果碰到一个net,转到genNet里去把这个处理完
{
i=this->genNet(i,result,l.allNetLine[netNum],l.allNetVia[netNum]);
netNum++;
}
if(stri.find("END NETS"))
{
//END这句不会在前面添加到findNet里面去
result+=stri+"\n";
return result;
}
}
}
throw string("NET cannot found");
}
};