我想找到一种方法来返回 Modelsim 中 VHDL 设计中某个路径的库的名称。
给定一个具有类似“/mega_tb/D0”的路径的 VHDL 设计。这是在一个不是“工作”的库中编译的,比如“libnwork”。我当然可以查看我的“do”文件以获取正确的库名称。或者我可以在 ModelSim 的 Library 选项卡中搜索。但我想拥有或创建一个稍后可以在 Tcl 脚本中使用的 modelsim 命令,以获取正确的库名称。
在 Tcl 脚本文件中查找内容的最简单方法之一是评估它。Tcl 在这方面非常擅长。当然,您不希望命令执行所有常规操作。相反,我们将在一个上下文中进行评估,在这个上下文中,除了产生我们想要的信息的命令之外,我们可以让一切都不做任何事情:
# Set up our evaluation context, 'worker'
interp create worker -safe
interp eval worker {proc unknown args {}}; # Our do-nothing handler
interp alias worker theInterestingCommand {} ourHandler
proc ourHandler args {
puts "We were called with: $args"
}
# Parse the file!
set f [open /the/file.tcl]
interp eval worker [read $f]
# Clean up
close $f
interp delete worker
现在您只需要theInterestingCommand
使用正确的名称并从参数中提取有趣的信息。哪个应该比较容易……</p>
我发现的唯一方法是使用命令
write report -tcl
这会打印一个很长的列表,我在其中使用正则表达式搜索库名称。就像是
set data [ write report -tcl]
foreach_regexp { _ type lib entity} $data{
if {$type == "Entity" && $entity == [entity_of_path /mega_tb/D0] } {
....
}
}
我当然必须定义我的“foreach_regexp”过程和“entity_of_path”过程。然后我可以使用 regsub 之类的东西来提取库名称。
我仍在寻找更好更简单的方法。