Many of the development tools, such as HDL simulators support Tcl commands in order to automate the designer’s workflow. It’s a very powerful and widely used tool; however sooner or later some of the Tcl’s features may become irritating. Like the default behavior of printing/echoing the result of of the command. Fortunately this can be easily fixed.
The default behavior
In any programming or scripting language, one the most frequently used statements is value assignment to a variable. In case of Tcl this is often done with the following command:
set a 1
However, once you execute this in a simulator’s (or other tool supporting Tcl), you will most likely see the following on the command prompt:
set a 1
1
This may not seem like a big deal – especially if you write each command manually. But a lot of the times dedicated Tcl scripts are created to automate the workflow and speed-up the designer’s work. Is this case there may (and probably will) be multiple set
statements. For instance, part of a script may look like:
...
set a 1
set b [expr $a +1]
...
puts "Hello, World!"
...
set c [pwd]
...
… and so on. Once you execute that script, apart from the the expected: Hello, World!
, you will most likely see the following on the command prompt:
1
2
"Hello, World!"
\path\to\your\folder
That’s not exactly what we want. So how can we fix that?
The solutions
Fortunately, there are some ways to fix that. The easiest one is to use a built-in command that turns off transcript echoing for the specified command. Some tools (such as ModelSim) provide such command. In case of Mentor’s ModelSim (and Questa), the command is: quietly
.
However, that solution may not work in all cases. As you can guess, ModelSim and Questa are not the only tools used, and not even the only HDL simulators. Many organizations and designers have a number of different workflows. Recently, I had a chance to fix a similar issue for my client. In this case the solution needed to work for ModelSim and Riviera Pro.
Luckily, there is a way to fix the described issue in all tools, with one simple Tcl hack. If you just want the solution, here it is:
proc quietly { arg } {
uplevel $arg; list
}
Now simply add quietly
word in front of set
command (unless you actually want the set value to be displayed) and the command prompt won’t get cluttered with unwanted printouts.
How does it work?
Let’s explain how this solution works. The first and the last lines:
proc quietly { arg } {
...
}
are obvious – it’s just a declaration of a Tcl procedure named: quietly
(you can choose any other name, if you want). Nothing new or interesting here.
The only remaining line is:
uplevel $arg; list
The uplevel
command just evaluates a command given in $arg
. I this case it simply executes a command after quietly
just like it’d be called without the quietly
command in the front. Nothing really special here. The actual solution is the last part: ; list
.
One of Tcl’s features (or standard behaviors), is that in case of interactive shell (like the command prompt in HDL development tools) the result of executed command is printed (what we’ve just discussed). Or more precisely: the result of the last executed command in a given line is printed. And this is what we are essentially using in this solution.
The list
command simply declares an empty and nameless list. The result of such declaration is null
. Literally nothing. Therefore, as the last executed command is the described list declaration, the result of the last executed command is nothing, so the printed value after command execution is also nothing.
Summing up
In other words: the solution presented above modifies the command such that, the command:
set a 1
becomes:
set a 1; list
Of course you can just add ; list
to the end of each line cluttering the command prompt, but you have to remember to do so, and how to do so (after a few months you may not remember the needed suffix). I think it’s a lot more intuitive to use a declared quietly
command instead.
Enjoy!
1 thought on “Prevent Tcl command printing every result”
Comments are closed.