A couple weeks ago, there was a good thread in the Digital Implementation Forums about managing buffering on nets between IOs and registers. The post touched on a number of interesting topics, but one of the fundamental building blocks I'd like to expand upon in this blog entry is the fundamental task of writing to and reading from a file: File I/O.
It may seem like second nature for folks who use TCL-based tools like Encounter regularly, and it's pretty much straight TCL that we use to write and read, but I hope having concise examples of how to do this within Encounter is a useful reference.
Reading From a File
Say for example you received a list of nets in a file that needed to be routed on upper metal layers. Here's an example of how you would read from that file and use the "setAttribute" command to apply that routing constraint. Say your file looked like this:
critical.nets:
n_5822
n_5828
n_5834
Here's how we'd do it:
set infile [open critical.nets "r"]
while {[gets $infile line] >= 0} {
setAttribute -net $line -bottom_preferred_routing_layer 5
}
close $infile
Writing To A File
Say we wanted to capture a list of all of the nets in the design that are connected to IO pins? Here's how we could do it:
set outfile [open io.nets "w"]
foreach net [dbGet [dbGet -u top.terms.net].name] {
puts $outfile $net
}
close $outfile
Redirecting Command Output To A File
Another scenario that's often useful is when we want to take command output that's echoed to the console and redirect it to a file. We can use the "redirect" command for this purpose. (Note: The command is not documented. This will be rectified in the next release.) Say for example you wanted to parse the output of the verifyGeometry command to see whether there were any violations. Here's one way you could do it:
redirect verifyGeometry > verifyGeometry.out
set infile [open verifyGeometry.out "r"]
while {[gets $infile line] >= 0} {
if {[string match *Verification* $line]} {
set nrViols [lindex $line 3]
}
}
close $infile
puts "verifyGeometry reported $nrViols violation(s)"
Tip: It's much easier to use "dbGet top.markers" to see whether there are violations in the design after running verifyGeometry:
encounter 1> dbGet top.markers
0x2aab94d740 0x2aab94d5f0
Separately, some commands like report_timing support ">" and ">>" redirection. For example:
report_timing > timing.report
We're looking to expand this easy ">" mechanism to include other commands in a future release.
I hope these examples are useful. Any related tips you'd like to share?
-Bob Dwyer