문제

Here is a .lib file snippet (used in chip design). So far I've done some text processing on the full .lib using tcl to rearrange the values block (see .lib code below) based on a single index_3 value (and now index_3 has to be blocked after usage) . I'm almost done with this project except that I'm having trouble with adding comments /* (at the start) and */ (at the end) to all index_3 lines (one instance shown in .lib example). Values within index_3 lines will be varying throughout the .lib file.

It should be printed like this finally /* index_3 ("0.094, 0.24, 3.39, 15.4, 13.94") ; */

Can someone help me as to where I need to zero in on index_3 and put the comments around it (while printing the 'line' variable) in this snippet of my code so far (this part of the code does regular expression matching). See my comment as to where I have thought of it to be appropriate to execute this. I apologize for the lack of proper indentation in advance. Thanks!

My code snippet for regex maching

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 }  

.lib file snippet

        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", \  
          );  
        } 

Reference: tcl text processing - rearrange values in rows and columns based on user defined value Special thanks to Brad Lanam and Glenn Jackman so far!

도움이 되었습니까?

해결책

I don't entirely trust the location of this

if {!$foundValues} {
    puts $outFile $line
}

Why is it outside the while loop?

But it seems that is where you should make your change

if {!$foundValues} {
    if {[string match "index_3" $line]} {
        puts $outFile "/* $line */"
    } else {
        puts $outFile $line
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top