Updated 5 min readTcl
Tcl scripting for EDA automation
Tcl scripting patterns for EDA flows: which tools run Tcl, namespaced libraries, required-variable checks, stage status lines and handing results to Python.
By the SkyCadEda engineering teamHow these notes are written
On this page
Tcl is the command language embedded in most digital implementation, timing and verification tools, so EDA automation in those tools means writing Tcl that runs inside the tool session. The scripts that last are organised in layers, stop on missing inputs, log one status line per stage and hand results to Python through files. The code below is plain Tcl 8.6 plus a few PrimeTime commands.
Where Tcl runs in an EDA flow
| Tool | Scripting language |
|---|---|
| Cadence Genus, Innovus, Tempus, Voltus | Tcl |
| Synopsys Design Compiler, Fusion Compiler, IC Compiler II, PrimeTime | Tcl |
| Synopsys Custom Compiler | Tcl |
| Siemens Calibre | SVRF rule decks; TVF (Tcl-based) for generated decks; Tcl in DESIGNrev (calibredrv) |
| Questa, Xcelium simulators | Tcl command interface |
| OpenROAD, Yosys | Tcl (OpenROAD also has Python) |
| Cadence Virtuoso | SKILL, not Tcl |
The last row matters: Virtuoso schematic and layout automation is written in SKILL (see Virtuoso layout automation with SKILL). Tcl knowledge transfers across the other tools because the language is the same, although each vendor's command set and object model differ.
Structure flow scripts in three layers
The common failure is the monolithic script: thousands of lines that configure the tool, run every step and post-process results in one file. It works until the first bug, and then nobody can isolate which stage misbehaved. Split it into three layers instead.
- A library layer of generic procedures (argument checks, logging, report parsing), versioned on its own.
- A tool wrapper layer, one file per tool and major version, that turns generic intents into tool commands.
- A project layer that holds only configuration and stage order, short enough to review in one sitting.
Namespaces keep the layers from colliding, and package provide lets project scripts ask for a specific library version:
# /proj/cad/tcl/flowlib/flowlib.tcl
package provide flowlib 1.2
namespace eval ::flowlib {
namespace export require_var stage
}Generate the pkgIndex.tcl for that directory with pkg_mkIndex, add the parent directory to auto_path and the project script loads it with package require flowlib 1.2. Log the loaded version at the start of each run so a behaviour change can be traced to a library release.
Stop on missing inputs
Unattended flows fail most often because a variable kept a stale or empty value, not because a tool crashed. A script that treats an empty corner list as nothing to do can finish cleanly with useless results. Required values such as the top cell, the corner list and the output directory should stop the run with a clear message:
proc ::flowlib::require_var {name} {
upvar #0 $name v
if {![info exists v] || $v eq ""} {
return -code error "required variable $name is not set"
}
return $v
}
# usage
set top [flowlib::require_var cfg(top)]
if {[llength [flowlib::require_var cfg(corners)]] == 0} {
error "cfg(corners) is empty"
}Optional behaviour, such as extra reports, can have defaults because leaving it out does not corrupt results. Keep all overrides in one array (cfg here), filled from the command line or an options file written by the orchestrator and checked against a list of allowed keys. Then there is one place to look when a value is wrong, and you can print the fully resolved array at the start of the log.
One status line per stage
A log is useful when it answers questions you did not anticipate. Give every stage a fixed-format status line with name, result and elapsed time, and keep verbose output in per-stage files. Tcl 8.6 try makes the wrapper short:
proc ::flowlib::stage {name body} {
set t0 [clock seconds]
try {
uplevel 1 $body
set status PASS
} on error {msg} {
set status FAIL
puts stderr "ERROR stage=$name: $msg"
}
puts [format "STAGE=%s STATUS=%s ELAPSED=%ds" \
$name $status [expr {[clock seconds] - $t0}]]
if {$status eq "FAIL"} {
return -code error "stage $name failed"
}
}In a PrimeTime run the project script then reads as a list of stages:
lappend auto_path /proj/cad/tcl
package require flowlib 1.2
flowlib::stage link {
read_verilog $cfg(netlist)
current_design [flowlib::require_var cfg(top)]
link_design
}
flowlib::stage constraints {
read_sdc $cfg(sdc)
}
flowlib::stage reports {
redirect rpt/check_timing.rpt { check_timing -verbose }
redirect rpt/timing.rpt { report_timing -max_paths 50 }
}Because every status line has the same fields, grep '^STAGE=' across hundreds of block logs gives a run-over-run comparison without parsing tool output. Also log the exit status of every external program you call with exec: a script that continues past a failed extraction will happily print a clean timing summary at the end.
Version shared libraries
Keep libraries in their own repository or a clearly separate directory, tag releases, and record the loaded version in every run log. Prefer additive changes: new procedures and new optional arguments rarely break callers, while renamed procedures and changed return formats break every project at once. When a breaking change is unavoidable, ship the new form under a new name for one release, migrate projects, then remove the old one.
Wrapper behaviour often differs between tool releases, so key the implementation on the tool version at load time (read the version string the tool reports and branch on it). One library tree can then serve a transition period where some blocks still run the older release.
Hand results to Python through files
Tcl owns the tool session; Python is better at scheduling runs, aggregating results and building dashboards. Make the boundary a file. The Tcl session ends by writing a small summary the orchestrator agreed to read:
set path [get_timing_paths -delay_type max -max_paths 1]
set fh [open results/summary.csv w]
puts $fh "metric,value"
puts $fh "wns_setup,[get_attribute $path slack]"
close $fhThe Python side reads that file and never re-derives numbers by scraping the full log. If the file is missing or unparseable, the orchestrator stops; it does not fall back to the previous run. In the other direction, the orchestrator writes the options file the Tcl argument check reads, so each side can be tested alone. The tool-agnostic Python wrappers post covers the Python half.
Review shared scripts like code
- The script stops on errors instead of continuing with partial state.
- Every required variable goes through a check like
require_var. - Paths are built from a few configurable roots, not hard-coded machine paths.
- Status lines name the stage, block and tool version.
- No license server names, internal hostnames or home directories in shared files.
- Each library file starts with a short header: what it provides, how to load it, one usage line.
SkyCadEda builds Tcl automation for design teams that need reliable custom IC, ASIC and CAD infrastructure flows, and we write and maintain this kind of Tcl for implementation and signoff; see Tcl/Tk scripting services.
Frequently asked questions
Which EDA tools are scripted in Tcl?
Cadence digital tools (Genus, Innovus, Tempus, Voltus), most Synopsys tools (Design Compiler, Fusion Compiler, IC Compiler II, PrimeTime, Custom Compiler), simulators such as Questa and Xcelium, Calibre DESIGNrev and Calibre TVF rule decks, and open-source tools such as OpenROAD and Yosys. Cadence Virtuoso is the main exception: it is scripted in SKILL, not Tcl.
Is Tk still used in EDA tools?
Rarely inside commercial tools, whose GUIs are now mostly built on other toolkits. Tcl is everywhere; Tk shows up mainly in small standalone utilities that CAD teams write for themselves, such as run launchers and report browsers.
When should a flow move from Tcl to Python?
Keep commands that run inside a tool session in Tcl, because that is the tool's native interface. Move scheduling, result aggregation, report comparison and dashboards to Python. Connect the two through files: the Tcl session writes a results file, Python reads it.
Related reading
More engineering notes
Working through a problem like this?
Tell us about your flow: the tools, the PDK, what is failing and when it needs to be clean.