我编写了此 TCL 代码来获取引脚详细信息并与层和矩形进行比较
proc fileinput {filename} {
set filedata [open $filename r]
set file1 [ read $filedata ]
close $filedata
set pindata [dict create]
foreach line [split $file1 \n] {
if {[string match "*PIN*" $line]} {
set pin [lindex $line 1]
}
if {[string match "*LAYER*" $line]} {
set layer [lindex $line 1]
dict lappend pindata $pin layer $layer
}
if {[string match *RECT* $line]} {
set rect [lindex $line 1 4]
dict lappend pindata $pin rect $rect
}
}
return $pindata
}
set pin_data1 [fileinput osi_hbmp_top_briscm_1.txt]
set pin_data2 [fileinput osi_hbmp_top_briscm_2.txt]
#last block
foreach pin_name [dict keys $pin_data1] {
set layer1 [dict get $pin_data1 $pin_name layer]
set layer2 [dict get $pin_data2 $pin_name layer]
if {$layer1 != $layer2} {
puts "pin not match"
} else {
puts $pin_name
}
}
在此代码中,我在最后一个代码块中收到错误。这两个文件包含相同格式的数据,但一些引脚名称不同。当它比较两个文件时会抛出错误。了解详情这个引脚只存在于第一个文件上,而第二个文件上没有这样的引脚。我可以知道我在代码中犯了什么错误吗?请指出我的错误:)我得到的错误是:-
key "i_hbmc_ieee1500_wsi_san" not known in dictionary
while executing
"dict get $pin_data2 $pin_name layer"
("foreach" body line 3)
invoked from within
"foreach pin_name [dict keys $pin_data1] {
set layer1 [dict get $pin_data1 $pin_name layer]
set layer2 [dict get $pin_data2 $pin_name lay..."
(file "aa.tcl" line 26)
供参考,文件的格式(文件中有缩进)
PIN i_hbmc_ieee1500_sel_wir
DIRECTION INPUT ;
USE SIGNAL ;
PORT
LAYER K3 ;
RECT 2090.163000 3265.856000 2090.476000 3265.920000 ;
END
END i_hbmc_ieee1500_sel_wir
PIN i_hbmc_ieee1500_cap_wr
DIRECTION INPUT ;
USE SIGNAL ;
PORT
LAYER K3 ;
RECT 2090.163000 3265.984000 2090.476000 3266.048000 ;
END
END i_hbmc_ieee1500_cap_wr
PIN i_hbmc_ieee1500_shft_wr
DIRECTION INPUT ;
USE SIGNAL ;
PORT
LAYER K3 ;
RECT 2090.163000 3265.728000 2090.476000 3265.792000 ;
END
END i_hbmc_ieee1500_shft_wr
答案1
proc fileinput {lef_path } { 设置 pin "" 设置 filedata [打开 $lef_path r]
设置文件1 [ 读取 $filedata ] 关闭 $filedata 设置 pindata [dict 创建] foreach 行 [拆分 $file1 \n] { 如果 {[字符串匹配"别针“$line]} { 设置 pin [lindex $line 1]
} 如果 {[字符串匹配”层" $line]} { 设置层 [lindex $line 1] dict lappend pindata $pin 层 $layer }
if {[字符串匹配矩形$line]} { 设置 rect [lindex $line 1 4] dict lappend pindata $pin rect $rect }
} 返回 $pindata } 设置 pin_data1 [fileinput osi_hbmp_top_briscm_1.txt ] 设置 pin_data2 [fileinput osi_hbmp_top_briscm_2.txt ] #最后一个块 foreach pin_name [dict keys $pin_data1] { 设置 layer1 [dict get $pin_data1 $pin_name layer] 设置 layer2 [dict get $pin_data2 $pin_name layer] if {$layer1 != $layer2} { puts "$pin_name :pin not match" } else { # puts $pin_name } }