Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
dsd1-10 / dsd-07=Verilog / esug.pdf
Скачиваний:
94
Добавлен:
05.06.2015
Размер:
1.38 Mб
Скачать

Ambit BuildGates Synthesis User Guide

Using Tcl within ac_shell and pks_shell

invalid command name “2”

The following examples show control structures:

while {$x == 1} {

# ‘break’ and ‘continue’ are supported in ‘while” and ‘for’ loops

}

for {set i 0} {$i < 10} {incr i} { puts $i

}

switch $x {

0 {puts “got a zero”}

1 {puts “got a one”}

default {puts “default case”}

# no break statements are needed in Tcl switch

}

Tcl supports associative array variables using the array command. Complex Tcl code requires associative array variables.

Tcl Commands

find Command

The find command identifies pieces of a design by name or by partial name regular expression, especially when setting constraints.

The Tcl language supports two methods of pattern matching: glob and regexp. The find command in ac_shell uses the glob style of matching by default, but supports the regular expression style if necessary using the -regexp option.

The glob style is used in the C-shell for matching file names and supports *, ?, and [] metacharacters. The pattern matches any names that match completely (including wildcard characters).

ac_shell> find -port -input clk*

Hierarchical names with wildcards are supported, such as:

September 2000

216

Product Version 4.0

Ambit BuildGates Synthesis User Guide

Using Tcl within ac_shell and pks_shell

ac_shell> find -port -input i*/*/clk_?

The optional regexp style is the same as that used by sed, grep, and lex. It is more powerful, but slightly different than the glob style in a richer set of supported meta-characters and that a match of a substring is sufficient to cause a pattern match.

Commonly used regexp meta-characters are . (a period) which matches any single character, ^ and $ which match the start and end, and * which matches 0 or more of the preceding character (or atom in the general case where an atom can be defined with parentheses).

Because matching any substring is sufficient to cause a match with the name, this finds all the input ports in the current module:

ac_shell> find -regexp -port -input

Beware of issuing a command like this with the -regexp option to identify port named se:

ac_shell> set_false_path -from \

[find -regexp -port -input se]

Using this command will match all input ports containing the string se. Instead, use the start and end meta-characters, enclosed in curly braces to prevent the Tcl engine from interpreting them itself:

ac_shell> set_false_path -from \

[find -regexp -port -input { ^se$ } ]

get_names Command

The get_names command is similar to the find command in that it returns a name from an object_id. The object_id is an ac_shell (not Tcl language) convention of assigning a unique integer to every design object, much like a pointer or handle. The find command goes from name to object_id, and get_names goes back:

ac_shell> find -port out

27462

ac_shell> get_names 27462

out

ac_shell> get_names [find -port out]

out

September 2000

217

Product Version 4.0

Ambit BuildGates Synthesis User Guide

Using Tcl within ac_shell and pks_shell

Most ac_shell commands that take a list of identifiers accept either names or object ids, since they are unambiguous (names cannot start with a number). Never enter numerical object ids manually.

Abbreviating Commands

Tcl allows command name abbreviations, but the abbreviation must be unique. The ac_shell command argument handling also follows this rule, which is helpful for interactive use. However, when writing project scripts it is a good idea to use the full command and argument names to avoid an ambiguity with new commands in a later release of the product or when additional user procedures have been defined.

Searching for Commands

When executing a command, Tcl searches a list of built-in commands, ac_shell commands, and user-defined procedures. Failing a match, it invokes a system call using the command, if it finds it in your path. This is very useful but can be confusing if you did not expect a system call to take place, especially if you are not aware of the command in your Unix path. Also, note that Unix shell features such as expanding ‘~’ to your home directory, are not available using this mechanism.

Accessing Environment Variables

Access environment variables using the global env Tcl array:

ac_shell> puts “Home directory is $env(HOME)”

Returning Unix Command Values

Obtain return values of Unix commands using the exec command:

set mydir [exec pwd]

-or-

set mydir [pwd] cd $mydir

September 2000

218

Product Version 4.0

Соседние файлы в папке dsd-07=Verilog