Contact us Start a Trial

Extending the Sigasi TCL interpreter

Sigasi project scripted targets can be configured to run TCL commands. The TCL environment comes with a built-in package that contains procedures to Import Third-Party Projects. If you need more functionality to be available in commands in order to import project definitions that Sigasi does not support yet, you can add it through standard TCL mechanisms to load definitions of additional procedures and packages. Refer to https://wiki.tcl-lang.org/page/TclIndex  for more details about these mechanisms.

The Sigasi TCL interpreter searches for additional definitions inside your project in the .sigasi/tcl directory. This directory is added to the TCLLIBPATH environment variable, which TCL uses to populate its auto_path .

Adding Procedures

If you would like to add a simple TCL procedure, you can do so by placing its definition in a .tcl file inside the .sigasi/tcl directory of your project and instructing the TCL interpreter where to find it by adding a .sigasi/tcl/tclIndex file with the following header:

# Tcl autoload index file, version 2.0

It is followed by rules on where to find each procedure. Each rule should be on a separate line:

set auto_index(new_procedure_name) [list source -encoding utf-8 [file join $dir file_with_new_procedure_definition.tcl]]

Example: Creating my_import procedure and using it in a scripted target

  1. Create a TCL file with my_import procedure definition, .sigasi/tcl/my_import.tcl:

    # my_import - Import project defined by CSV compilation order
    # Usage:
    #   my_import path/to/compilation_order.csv [additional qrun arguments]
    # CSV format:
    #   library_name, path/to/hdl_file
    proc my_import {csv_file {qrun_args {}}} {
      set fh [open $csv_file r]
      while {[gets $fh line] >= 0} {
        set comma [string first , $line]
        if {$comma < 0} continue
        set lib  [string trim [string range $line 0 [expr {$comma-1}]]]
        set path [string trim [string range $line [expr {$comma+1}] end]]
        exec qrun -work $lib {*}$qrun_args $path
      }
      close $fh
    }
    

    Note: Refer to the Supported Compilers article for details about the qrun compilation command.

  2. Create a TCL index file to instruct the TCL interpreter where to find my_import definition, .sigasi/tcl/tclIndex:

    # Tcl autoload index file, version 2.0
    
    set auto_index(my_import) [list source -encoding utf-8 [file join $dir my_import.tcl]]
    
  3. Use the newly added my_import procedure in a scripted target, project.sigasi:

    {
      "name": "my_import_example",
      "targets": {
        "rtl": {
          "interpreter": "tcl",
          "command": "my_import compilation_order.csv"
        }
      }
    }
    

Adding Packages

If you would like to add additional TCL packages, you can put them inside the .sigasi/tcl directory of your project. This will make it possible to load these packages by the package require package_name TCL command, allowing usage of procedures from the package.

Example: Creating my_pkg package with my_pkg_import procedure and using it in a scripted target

  1. Create a package index file that specifies the package name, version, and .tcl file with package definitions, .sigasi/tcl/my_pkg/pkgIndex.tcl:
    package ifneeded my_pkg 1.0 [list source [file join $dir my_pkg.tcl]]
    
  2. Create .tcl file with package definitions, .sigasi/tcl/my_pkg/my_pkg.tcl:
    package provide my_pkg 1.0
    
    # my_pkg_import - Import project defined by CSV compilation order
    # Usage:
    #   my_pkg_import path/to/compilation_order.csv [additional qrun arguments]
    # CSV format:
    #   library_name, path/to/hdl_file
    proc my_pkg_import {csv_file {qrun_args {}}} {
      set fh [open $csv_file r]
      while {[gets $fh line] >= 0} {
        set comma [string first , $line]
        if {$comma < 0} continue
        set lib  [string trim [string range $line 0 [expr {$comma-1}]]]
        set path [string trim [string range $line [expr {$comma+1}] end]]
        exec qrun -work $lib {*}$qrun_args $path
      }
      close $fh
    }
    

    Note: Refer to Supported Compilers article for details about qrun compilation command.

  3. Use the newly added my_pkg package in a scripted target, project.sigasi:
    {
      "name": "my_pkg_example",
      "targets": {
        "rtl": {
          "interpreter": "tcl",
          "command": "package require my_pkg; my_pkg_import compilation_order.csv"
        }
      }
    }
    

If you want a procedure from a package to be available without using package require my_pkg in a target command, you can do it with the following TCL index file (similar to adding procedures):

  1. Add rule to load corresponding package with my_pkg_import definition to TCL index file, .sigasi/tcl/tclIndex:
    # Tcl autoload index file, version 2.0
    
    set auto_index(my_pkg_import) [list package require my_pkg]
    
  2. Use the procedure my_pkg_import without loading the package in a scripted target, project.sigasi:
    {
      "name": "my_pkg_import_example",
      "targets": {
        "rtl": {
          "interpreter": "tcl",
          "command": "my_pkg_import compilation_order.csv -2008 -sv"
        }
      }
    }