Python用于网表处理( 三 )


7 ifold_modelinstr:
8 returnre.sub(r"\b" + old_model + r"\b", new_model, str)
9 else:
10 returnstr
11
12
13# define a function for device resize
14def resize_device(new_size, str):
15 ifre.search(r'(W=.*[un])(.*)(L=.*[un])', str):
16 returnre.sub(r'(W=.*[un])(.*)(L=.*[un])', r"\1*" + new_size + r"\2"
17 + r"\3*" + new_size, str)
18 elifre.search(r'(L=.*[un])(.*)(W=.*[un])', str):
19 returnre.sub(r'(L=.*[un])(.*)(W=.*[un])', r"\1*" + new_size + r"\2"
20 + r"\3*" + new_size, str)
21 elifre.search(r'(AREA)', str):
22 returnre.sub(r'(?P\bAREA=)', r"\g" + new_size + "*" + new_size + "*", str)
23 else:
24 returnstr
25
26
27iflen(sys.argv)!= 5:
28 print("Error, you need 5 arguments")
29 print("Usage: python(python3) ICSkillSharing.py xxx.cdl replace old_model new_model")
30 print("Usage: python(python3) ICSkillSharing.py xxx.cdl resize x new_size")
31
32elif(sys.argv[2]!="replace")and(sys.argv[2]!="resize"):
33 print('Error, the third arguments should be "replace" or "resize"')
34 print("Usage: python(python3) ICSkillSharing.py xxx.cdl replace old_model new_model")
35 print("Usage: python(python3) ICSkillSharing.py xxx.cdl resize 1 new_size")
36
37else:
38 os.system("copy" + " " + sys.argv[1] + " " + sys.argv[1]+".bk") # for
39 # Windows
40 # os.system("cp" + " " + sys.argv[1] + " " + sys.argv[1]+".bk") # for Linux
41 withopen(sys.argv[1]+".bk", 'r')asread_file, open(sys.argv[1],
42 'w') aswrite_file:
43 forlineinread_file:
44 ifsys.argv[2] == "replace":
45 write_file.write(replace_model(sys.argv[3], sys.argv[4], line))
46 ifsys.argv[2] == "resize":
47 write_file.write(resize_device(sys.argv[4], line))
48
49print("Finish!")
上下、左右滑动可以查看更多内容哦!
上面脚本使用时可以根据需要传递参数:replace或者resize , 使用时在终端输入命令:
1python replace_resize_v2.py bgr.cdl resize 1 0.9
2python replace_resize_v2.py bgr.cdl replace p33 pch3
使用上面命令相应的替换结果如下 , 用户可以采用同样方法替换其它器件模型或者改变器件尺寸:
1************************************************************************
2* auCdl Netlist:
3*
4* Library Name: ref_circuits
5* Top Cell Name: bgr
6* View Name: schematic
7* Netlisted on: May 20 22:40:47 2020
8************************************************************************
9
10*.BIPOLAR
11*.RESI = 2000
12*.RESVAL
13*.CAPVAL
14*.DIOPERI
15*.DIOAREA
16*.EQUATION
17*.SCALE METER
18*.MEGA
19.PARAM
20
21
22
23************************************************************************
24* Library Name: ref_circuits
25* Cell Name: bgr
26* View Name: schematic
27************************************************************************
28
29.SUBCKT bgr GNDA PD SUB VBG VDDA
30*.PININFO PD:I VBG:O GNDA:B SUB:B VDDA:B
31XMM1 net30 PDN net56 SUB n33 W=4u*0.9 L=350n*0.9 m=1
32XMM5 net29 net29 net28 SUB n33 W=4u*0.9 L=1u*0.9 m=1
33XMM11 net30 net29 net50 SUB n33 W=4u*0.9 L=1u*0.9 m=1
34XMM12 net36 net29 net49 SUB n33 W=4u*0.9 L=1u*0.9 m=1
35XMM19 VBG PDP GNDA SUB n33 W=4u*0.9 L=350n*0.9 m=1
36XMM16 net56 net19 GNDA SUB n33 W=4u*0.9 L=350n*0.9 m=1
37XMM3 net19 VBG GNDA SUB n33 W=2u*0.9 L=350n*0.9 m=1
38XMM6 net28 net28 GNDA SUB n33 W=4u*0.9 L=1u*0.9 m=1
39XMM22 PDN PD GNDA SUB n33 W=4u*0.9 L=350n*0.9 m=1
40XMM25 net50 net28 GNDA SUB n33 W=4u*0.9 L=1u*0.9 m=2
41XMM13 net49 net28 GNDA SUB n33 W=4u*0.9 L=1u*0.9 m=2
42XMM17 PDP PDN GNDA SUB n33 W=4u*0.9 L=350n*0.9 m=1
43QQ1 SUB SUB INP pnp33a4 M=1 AREA=0.9*0.9*4e-12
44QQ0 SUB SUB net55 pnp33a4 M=8 AREA=0.9*0.9*4e-12
45XR6 net54 VBG SUB rhrpo_3t_ckt M=1 W=2u*0.9 L=14u*0.9
46XR3 net54 VBG SUB rhrpo_3t_ckt M=1 W=2u*0.9 L=7u*0.9
47XR2 net51 net52 SUB rhrpo_3t_ckt M=1 W=2u*0.9 L=7u*0.9
48XR5 net51 net52 SUB rhrpo_3t_ckt M=1 W=2u*0.9 L=14u*0.9
49XR4 INP net51 SUB rhrpo_3t_ckt M=1 W=2u*0.9 L=168u*0.9
50XR1 INN net54 SUB rhrpo_3t_ckt M=1 W=2u*0.9 L=168u*0.9
51XR0 net55 INN SUB rhrpo_3t_ckt M=1 W=2u*0.9 L=21u*0.9
52XMM18 net30 PDN VDDA VDDA pch3 W=4u*0.9 L=300n*0.9 m=1
53XMM7 net22 net22 VDDA VDDA pch3 W=2u*0.9 L=1u*0.9 m=1
54XMM14 net32 net30 VDDA VDDA pch3 W=4u*0.9 L=1u*0.9 m=2
55XMM15 net29 net30 VDDA VDDA pch3 W=4u*0.9 L=1u*0.9 m=1
56XMM23 net52 net30 VDDA VDDA pch3 W=4u*0.9 L=1u*0.9 m=4
57XMM24 VBG net30 VDDA VDDA pch3 W=4u*0.9 L=1u*0.9 m=4
58XMM20 net36 net36 VDDA VDDA pch3 W=8u*0.9 L=2u*0.9 m=2
59XMM21 net30 net36 VDDA VDDA pch3 W=8u*0.9 L=2u*0.9 m=2
60XMM4 net21 net21 net22 VDDA pch3 W=2u*0.9 L=1u*0.9 m=1
61XMM8 net49 INN net32 net32 pch3 W=12u*0.9 L=1u*0.9 m=2
62XMM9 net50 INP net32 net32 pch3 W=12u*0.9 L=1u*0.9 m=2
63XMM0 net20 net20 net21 VDDA pch3 W=2u*0.9 L=1u*0.9 m=1