Tcl for EDA · lesson 1

Why every EDA tool speaks Tcl

What Tcl is, why synthesis, place and route and timing tools all embed it, and how a script reaches the design database.

7 min read · Free, no login

Open the command line of Genus, Innovus, Design Compiler, ICC2 or PrimeTime and you land in the same place: a Tcl prompt. The tool's own commands, such as place_opt_design or report_timing, are added to a language that already exists. This lesson explains why that choice was made, what you get from it, and the few ideas you must hold before writing a single script.

Reading time: about 7 minutes.

1.1 What Tcl is

Tcl (the Tool Command Language) is a small scripting language built to be embedded in other programs. A tool author links the Tcl interpreter into the application, registers the application's functions as Tcl commands, and gets a full scripting language without designing one. Users get loops, variables, procedures and file handling for free. The tool author gets one stable language that every customer already knows.

Let us consider what that means for you. When you type setOptMode -opt_add_insts true in Innovus, the Tcl interpreter reads the line, finds a command called setOptMode, and hands it the words that follow. The command belongs to the tool. The reading, the variables around it and the foreach loop you may put it in belong to Tcl.

1.2 Two places to run Tcl

You can run Tcl in two different places, and it helps to keep them apart.

  1. tclsh is a plain interpreter that ships with Tcl. It knows the language and nothing about any design. This is where you learn and test your scripting logic.
  2. The tool prompt is the same interpreter with extra commands. Everything that works in tclsh works here too, and in addition you can call the tool's commands.

Most of this course uses tclsh, because a script that parses a report or loops over a list of names does not need a tool. When a small tool example helps, it is shown in a separate block and labelled. Check which Tcl version a tool uses by running puts [info patchlevel] at its prompt. The examples in this course were run on Tcl 8.6.12.

puts "hello from [info patchlevel]"

This prints:

hello from 8.6.12

1.3 Everything is a command

Tcl has almost no syntax. There are no keywords in the usual sense. set, if, foreach and proc are all ordinary commands that take arguments. A script is a sequence of commands, one per line (or separated by semicolons), and each command is a list of words. The first word names the command, and the rest are its arguments.

set period 2.0
puts "period is $period ns"
puts "half period is [expr {$period / 2}] ns"

This prints:

period is 2.0 ns
half period is 1.0 ns

Notice three commands: set, puts and expr. The square brackets run a command and use its result as a word. The dollar sign reads a variable. Lesson 2 shows exactly how these work. For now, hold on to the rule that every line is a command and every command is a list of words.

Figure 1.1 shows how a script, the interpreter and the tool fit together.

Your script(.tcl file ortyped command)Tcl interpreterparse, substitute,evaluateTool commands(Innovus, Genus,your own procs)Design databaseand report filesEvery line you type is a command: a list of words.The interpreter turns the words into a call; the tool's commands do the design work.A Tcl error stops the script unless you catch it.
Figure 1.1 – Your script is read by the Tcl interpreter, which calls the tool’s own commands against the design database.

1.4 Everything is a string

Tcl treats values as strings. A number, a list and a file name are all text, and the interpreter converts between meanings when a command needs it. A variable holding 10 and a variable holding the text "10" are the same thing.

set a 10
set b "10"
puts [expr {$a == $b}]
puts [string length 12345]

This prints:

1
5

The consequence for EDA is practical. Names of cells, nets and pins, numbers from reports and whole lines from a log all arrive as strings, and you can search and slice them with the same small set of commands. The price is that Tcl will not warn you when you treat a list as a string or the reverse. Lessons 4 and 12 return to this.

1.5 A command is a list

Because a command is a list of words, you can build one as data and run it later. This is how flow scripts assemble tool commands from settings.

set words [list set clk_period 2.0]
puts [llength $words]
eval $words
puts $clk_period

This prints:

3
2.0

The list holds three words, and eval runs them as a command. You will use this idea carefully in Lesson 11. It is powerful, and it is also the source of the most common quoting bugs.

1.6 Scripts, source and batch runs

A script is a text file of commands. You run it with source, which reads the file and evaluates each command in turn.

Legacy UI. To be run at the Innovus prompt. Check the options against your release with source -help.

source -echo run_place.tcl

The -echo option prints each command as it runs, which makes a log easy to read. Without options, the global enc_source_verbose decides how much is printed.

For a run with no window, the Common UI synthesis lab flow starts the tool with the script as an argument. To be run from a shell, with the options checked in your release:

innovus -synthesis -stylus -no_gui -files run.tcl -log run1 -overwrite

The Legacy and Common UI command sets are different, but both are Tcl. A foreach loop is written the same way in each. In this course every tool example is labelled so you always know which command set a line belongs to.

1.7 What Tcl is not

Tcl is not a fast numerical language and not a type-checked one. A loop over a million cells in Tcl is slow compared with a command the tool runs in its own code. That is the reason tool commands such as get_cells -filter exist: let the tool select, and let Tcl decide what to do with the result. Lesson 10 returns to this balance.

1.8 What goes wrong without Tcl knowledge

A designer who copies tool commands from a colleague's script can run a flow. The trouble starts when a command needs to change. A hard-coded cell name needs to become a loop over many cells. A report must be read to decide whether to continue. A step fails in the middle of a night run and nothing recorded why. Each of those needs a few Tcl ideas: variables, lists, string and regular expression commands, catch, procedures and files. The rest of this course covers them in that order.

1.9 Why an interviewer asks about this

Physical design and CAD interviews often begin with Tcl because it shows how a candidate really works. Likely questions: "what is the difference between tclsh and the tool shell", "why is everything a string in Tcl", and "how would you run the same command over a list of cells". A good answer names the interpreter, explains that the tool adds commands to it, and describes a foreach loop over a list.

Key takeaways

  • EDA tools embed a Tcl interpreter and add their own commands, so Tcl skill carries across Innovus, Genus and the rest.
  • A script is a list of commands, and every command is a list of words.
  • Values are strings, and you convert meanings by choosing the right command.
  • Tool commands do the heavy work on the design, and Tcl decides what to run and what to do with the result.