【发布时间】:2014-04-11 09:38:55
【问题描述】:
如何以x y 的形式将 Modelsim 信号值检索到 tcl 中,以便单独处理 x 和 y?
目前我在 tcl 中有这条线来跟踪信号值
当 {/currentstate/comp_occupy} {set comp [exa {/currentstate/comp_occupy}]}
此信号是 Modelsim 中的二维数组,在小部件中显示为 x y。
这个 sn-p 应该跟踪那个变量
trace variable comp w grid_monitor
proc grid_monitor {name arrayindex op} {
global comp flag_ttt cells
if {$flag_ttt == 1} {
puts $comp
puts [llength $comp]
}
}
我从这个过程中得到的是这样的{x y},但我不知道如何将 x 和 y 分开。首先我认为这是一个列表,但 llength 返回 1!
知道我该怎么做吗?或者更确切地说,我怎样才能把它变成一个合适的列表?
谢谢
【问题讨论】:
-
你的进程中
puts $comp的输出是什么? -
例如这个
{1 3}。它看起来像一个列表,但似乎都是一个元素。 -
好吧,如果你在列表中有它,比如
[list {1 3}]并使用puts [lindex [list {1 3}] 0],你会得到{1 3}:这是1 个元素。你需要拆分它。试试puts [llength [split $comp]]。 -
好的,这就证明
$comp不是一个列表,而是一个字符串。我认为最好先使用puts [string trim $comp "{}"],然后使用puts [llength [string trim $comp "{}"]]。string trim将删除字符串左右两边的字符{和}。 -
好吧,结合我们所讨论的内容,您可以将这一行放在
puts $comp的上方以生成一个列表:set comp [split [string trim $comp "{}"]]。如果你想得到 x = 3 和 y = 1,你可以使用lindex或lassign(如果你有 Tcl 8.5 或更高版本)。