Advertisement
Guest User

simple tcl examples (c) Mentor Graphics

a guest
Oct 20th, 2015
833
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 3.50 KB | None | 0 0
  1. # (c) Mentor Graphics modelsim_tcl.pdf
  2.  
  3.  
  4. #-----
  5. #    Tcl while Loop
  6. # This example uses the Tcl while loop to copy a list from variable a to variable b, reversing the order of the
  7. # elements along the way:
  8.  
  9. set b [list]
  10. set i [expr {[llength $a] - 1}]
  11. while {$i >= 0} {
  12.    lappend b [lindex $a $i]
  13.    incr i -1
  14. }
  15.  
  16. #-----
  17. #    Tcl for Command
  18. # This example uses the Tcl for command to copy a list from variable a to variable b, reversing the order of the
  19. # elements along the way:
  20.  
  21. set b [list]
  22. for {set i [expr {[llength $a] - 1}]} {$i >= 0} {incr i -1} {
  23.    lappend b [lindex $a $i]
  24. }
  25.  
  26. #-----
  27. #    Tcl foreach Command
  28.  
  29. # This example uses the Tcl foreach command to copy a list from variable a to variable b, reversing the order of the # elements along the way (the foreach command iterates over all of the elements of a list):
  30.  
  31. set b [list]
  32. foreach i $a { set b [linsert $b 0 $i] }
  33.  
  34. #-----
  35. #    Tcl break Command
  36.  
  37. # This example shows a list reversal as above, this time aborting on a particular element using the Tcl break command:
  38.  
  39. set b [list]
  40. foreach i $a {
  41.    if {$i = "ZZZ"} break
  42.    set b [linsert $b 0 $i]
  43. }
  44.  
  45. #-----
  46. #    Tcl continue Command
  47.  
  48. # This example is a list reversal that skips a particular element by using the Tcl continue command:
  49.  
  50. set b [list]
  51. foreach i $a {
  52.    if {$i = "ZZZ"} continue
  53.    set b [linsert $b 0 $i]
  54. }
  55.  
  56. #-----
  57. #    Access and Transfer System Information
  58.  
  59. # This example works in UNIX only. In a Windows environment, the Tcl exec command will execute compiled files only,
  60. # not system     --sets the breakpoint to call set_datecommands.) The example shows how you can access system information and transfer it into VHDL variables
  61. # or signals and Verilog nets or registers. When a particular HDL source breakpoint occurs, a Tcl function is called # that #gets the date and time and deposits it into a VHDL signal of type STRING. If a particular environment
  62. # variable (DO_ECHO) is set, the function also echoes the new date and time to the transcript file by examining the #  VHDL variable.
  63.  
  64. # (in VHDL source):
  65. # signal datime : string(1 to 28) := " ";
  66. # (on VSIM command line or in a DO file script):
  67.  
  68. proc set_date {} {
  69.    global env
  70.    set do_the_echo [set env(DO_ECHO)]
  71.    set s [clock format [clock seconds]]
  72.    force -deposit datime $s
  73.    if {do_the_echo} {
  74.       echo "New time is [examine -value datime]"
  75.    }
  76. }
  77.  
  78. bp src/waveadd.vhd 133 {set_date; continue}
  79. #    --sets the breakpoint to call set_date
  80.  
  81. #-----
  82. #    Tcl Used to Specify Compiler Arguments
  83.  
  84. # This example specifies the compiler arguments and lets you compile any number of files.
  85.  
  86. set Files [list]
  87. set nbrArgs $argc
  88. for {set x 1} {$x <= $nbrArgs} {incr x} {
  89.    set lappend Files $1
  90.    shift
  91. }
  92. eval vcom -93 -explicit -noaccel std_logic_arith $Files
  93.  
  94. #-----
  95. #    Tcl Used to Specify Compiler Arguments—Enhanced
  96.  
  97. # This example is an enhanced version of the last one. The additional code determines whether the files are VHDL or   # Verilog and uses the appropriate compiler and arguments depending on the file type. Note that the script assumes
  98. # your VHDL files have a .vhd file extension.
  99.  
  100. set vhdFiles [list]
  101. set vFiles [list]
  102. set nbrArgs $argc
  103. for {set x 1} {$x <= $nbrArgs} {incr x} {
  104.    if {[string match *.vhd $1]} {
  105.       lappend vhdFiles $1
  106.    } else {
  107.       lappend vFiles $1
  108.    }
  109.    shift
  110. }
  111. if {[llength $vhdFiles] > 0} {
  112.    eval vcom -93 -explicit -noaccel std_logic_arith $vhdFiles
  113. }
  114. if {[llength $vFiles] > 0} {
  115.    eval vlog $vFiles
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement