这是一个.lib文件片段(用于芯片设计)。到目前为止,我已经使用tcl对完整的.lib进行了一些文本处理,以基于单个index_3值重新排列值块(参见下面的.lib代码)(现在index_3必须在使用后被阻塞)。我几乎完成了这个项目,除了我有麻烦添加注释/*(在开始)和*/(在结束)到所有index_3行(在.lib示例中显示的一个实例)。在.lib文件中,index_3行中的值将会变化。
应该打印成这样,最后/* index_3 ("0.094, 0.24, 3.39, 15.4, 13.94") ; */
有人可以帮助我在哪里我需要在index_3上归零,并把它周围的注释(同时打印'line'变量)在我的代码片段到目前为止(这部分代码做正则表达式匹配)。看到我的评论,我认为它是适当的执行这一点。我为没有适当的缩进提前道歉。谢谢!
正则表达式处理的代码片段
set inFile [open "C:/Tcl/official/ref.lib" r]
set outFile [open "C:/Tcl/official/mod.lib" w]
set inval false
set found_cell 0
set foundValues 0
set found_setup 0
set found_fall 0
set DETECT_END_SYNTAX {);}
while { [gets $inFile line] >= 0 } {
set d $col(3)
# extract index
set id0 "[dict values [dict get $falldata constraints constraint $d 0]]"
set id1 "[dict values [dict get $falldata constraints constraint $d 1]]"
set id2 "[dict values [dict get $falldata constraints constraint $d 2]]"
set id3 "[dict values [dict get $falldata constraints constraint $d 3]]"
set id4 "[dict values [dict get $falldata constraints constraint $d 4]]"
set newvalues [list $id0 $id1 $id2 $id3 $id4]
# ZERO IN ON VALUES BLOCK OF TYPE SETUP_RISING & FALL_CONSTRAINT TO MANIPULATE VALUES
if { [regexp {setup_rising} $line] } { set found_setup 1 }
if { [regexp {hold_rising} $line] } { set found_setup 0 }
if { $found_setup } {
if { [regexp {fall_constraint} $line] } { set found_fall 1 }
if { $found_fall } {
#### NEED TO REGEX index_3 HERE and BLOCK IT!! #######
if {[regexp {values} $line]} {
# find 'values' keyword in .lib as start point
set foundValues 1
}
if {$foundValues} {
# find ' ); ' (end syntax) in .lib as end point
if { [regexp $DETECT_END_SYNTAX $line] } {
set foundValues 0
set found_setup 0
set found_fall 0
puts $outFile " values ( \"
foreach elem $newvalues {
puts $outFile [format " "%s", \" [join $elem {,}]]
}
}
}
}
}
if {!$foundValues} {
puts $outFile $line
}
{ REST OF CODE FOR TEXT PROCESSING ON 'REGEXED' VALUES OF CONCERN }
。库文件片段
timing () {
related_pin : "clk";
timing_type : setup_rising;
fall_constraint (constraint_template_5X5) {
index_1 ("0.01, 0.05, 0.12, 0.2, 0.4");
index_2 ("0.005, 0.025, 0.06, 0.1, 0.3");
index_3 ("0.094, 0.24, 3.39, 15.4, 13.94") ;
values (
"1.1, 1.2, 1.3, 1.4, 1.5",
"2.1, 2.2, 2.3, 2.4, 2.5",
"3.1, 3.2, 3.3, 3.4, 3.5",
"4.1, 4.2, 4.3, 4.4, 4.5",
"5.1, 5.2, 5.3, 5.4, 5.5",
"6.1, 6.2, 6.3, 6.4, 6.5",
"7.1 ,7.2, 7.3, 7.4, 7.5",
"8.1, 8.2, 8.3, 8.4, 8.5",
"9.1, 9.2, 9.3, 9.4, 9.5",
"10.1,10.2,10.3,10.4,10.5",
"11.1,11.2,11.3,11.4,11.5",
"12.1,12.2,12.3,12.4,12.5",
"13.1,13.2,13.3,13.4,13.5",
"14.1,14.2,14.3,14.4,14.5",
"15.1,15.2,15.3,15.4,15.5",
"16.1,16.2,16.3,16.4,16.5",
"17.1,17.2,17.3,17.4,17.5",
"18.1,18.2,18.3,18.4,18.5",
"19.1,19.2,19.3,19.4,19.5",
"20.1,20.2,20.3,20.4,20.5",
"21.1,21.2,21.3,21.4,21.5",
"22.1,22.2,22.3,22.4,22.5",
"23.1,23.2,23.3,23.4,23.5",
"24.1,24.2,24.3,24.4,24.5",
"25.1,25.2,25.3,25.4,25.5",
);
}
参考:tcl文本处理-根据用户定义的值重新排列行和列中的值特别感谢布拉德·拉南和格伦·杰克曼!
我不完全相信这个
的位置if {!$foundValues} {
puts $outFile $line
}
为什么在while循环之外?
但这似乎是你应该做出改变的地方
if {!$foundValues} {
if {[string match "index_3" $line]} {
puts $outFile "/* $line */"
} else {
puts $outFile $line
}
}