I am submitting two alternate methods just for the sake of variety.
Method 1: Using the unknown
Handler
Here is a different approach: since the input file appears to be a Tcl script, as soon as we detect a line with set_false_path
, we can evaluate that line in order to extract the PINs. In order for this to work, we setup a procedure called unknown
to catch all unknown procedures. In this case, we are interested in get_ports
, get_pins
, get_abc
...:
# proc unknown is invoked for all unknown procedures: those that are
# called without previously defined.
proc unknown {cmdName args} {
global outFile
# List of procedures with PINs as arguments
set pinProcs {get_ports get_pins get_abc}
# If the procedure has PINs as arguments, we extract those PINs
# and write to a file
if {[lsearch -exact $pinProcs $cmdName] != -1} {
eval "set args $args"; # Remove the surrounding braces {}
foreach arg $args { puts $outFile $arg }
}
}
set inFile [open "input_file.txt"]
set outFile [open "output_file.txt" "w"]
while {[gets $inFile line] != -1} {
if {[lindex [split $line " "] 0] eq "set_false_path"} {
eval $line; # Tells Tcl interpreter to interpret the line
}
}
close $inFile
close $outFile
This method has a couple of advantages: it relies on Tcl to correctly parses the input lines and we don't have to deal with messy regular expressions. The disadvantages include the need to manually keeping track of which procedure we are interested in (see pinProcs
, above).
Method 2: Create Our Own set_false_path
Procedure
Similar to the above, this time, we setup our own set_false_path
procedure to extract all the PINs that follow the following flags: -to
, -from
, and -through
. The advantage of this approach is we don't have to manually keep a list of procedure names (see pinProcs
).
# Our own proc, which returns a list of PINs
proc set_false_path {args} {
set result {}
for {set i 0} {$i < [llength $args]} {incr i} {
set token [lindex $args $i]
if {[lsearch -exact {-to -from -through} $token] != -1} {
incr i
set token [lindex $args $i]
lappend result {*}[lindex $args $i]
}
}
return $result
}
# proc unknown is invoked for all unknown procedures: those that are
# called without previously defined.
proc unknown {cmdName args} {
eval "set args $args"; # Remove the surrounding braces {}
return $args
}
set inFile [open "input_file.txt"]
set outFile [open "output_file.txt" "w"]
while {[gets $inFile line] != -1} {
if {[lindex [split $line " "] 0] eq "set_false_path"} {
foreach pin [eval $line] {
puts $outFile $pin
}
}
}
close $inFile
close $outFile