Parse Configuration Files
It is common for a flow to depend on an existing configuration file.
We do not recommend the use of configuration files for this purpose, because they tend to introduce a dependency between the file and the flow that is likely to invalidate an entire flow even for simple changes to the config file.
Nevertheless, since the use of such files is widespread, we want to show you how you can easily extract information from those files to control your flows.
Every configuration file has a slightly different syntax. In the following table, it
is assumed that you have a configuration file that contains simple assignments,
comments and empty lines. We trust you will know how to adapt the code fragments
below to your particular application.
# Fragment of fictitious configuration file.
VERILOG = finsim
SYNTH = autosyn
PLACER = se
ROUTER = apollo
# More parameters.
DO_DRC = 0
DO_LVS = 1
To parse the configuration file, we can use standard Tcl:
proc parseConfigurationFile { file } {
# An array to collect the parameters.
global PARAM
# Open the file and read one line at a time.
set fp [open $file "r"]
while { [gets $fp line] >= 0 } {
if [regexp {^#} $line] continue; # Discard comments.
if [regexp {(.+)=(.+)} $line all var value] {
set var [string trim $var]
set value [string trim $value]
set PARAM($var) $value
}
}
close $fp
}