我在VCS UCLI(即命令行界面)中工作,并且无法让VCS显示各种状态变量,typedef的枚举类型,值作为名称而不是数字 . 例如,我有一些像这样的SystemVerilog:
typedef enum logic [1:0] {A, B, C} state_t;
state_t s;
...
现在在ucli,我想看到 s
的值(说它在状态A中)所以我输入类似的东西:
ucli% get s
0
ucli% get s -radix symbolic
0
ucli% show s -value
s 0
ucli% show s -value -radix symbolic
s 0
ucli% show s -value -type
s 0 { ENUM state_t { {A 0} {B 1} {C 2} } }
(或类似的东西) . 我已经阅读了ucli用户指南,它似乎是符号基数,我所知道的唯一一个可能接近的基数,只使用枚举中的原始值,而不是枚举名称 . 我尝试使用ucli( ucli% call {$display("%s", s.name())}
)中的call命令为变量 s
调用 .name()
方法,但它似乎不受支持 . 我知道VCS有能力打印枚举名称,它当然可以在DVE中,但我很难找到方法来展示我在ucli .
有谁知道如何让ucli打印枚举名称而不是查询时的数字?枚举类型的基数是某种方式(在DVE中用户定义?),使用一些SystemVerilog系统调用来获取名称,类似的东西?
(注意,我知道我可以使用DVE,但我正在尝试使用ucli简单地为潜在用户设置接口,这是出于教育目的而我想要掩盖很多ucli接口(和一般的VCS接口)不要压倒学生并轻松获得一些变量;我将vcs ucli变成一个简单的处理器模拟器)
UPDATE
我提出了一个非常hacky的解决方案,但我真的想要一个更好的方法 . 我快速写了我自己的show包装器(称为eshow)如果设置了-radix枚举,请用枚举名替换任何-value:
#
# An extension of show to include "-radix enum"
#
# Borrowed from http://wiki.tcl.tk/17342
# Credit to Richard Suchenwirth (12-8-2006)
proc getopt {_argv name {_var ""} {default ""}} {
upvar 1 $_argv argv $_var var
set pos [lsearch -regexp $argv ^$name]
if {$pos>=0} {
set to $pos
if {$_var ne ""} {
set var [lindex $argv [incr to]]
}
set argv [lreplace $argv $pos $to]
return 1
} else {
if {[llength [info level 0]] == 5} {set var $default}
return 0
}
}
proc eshow {args} {
set argv $args
# If radix is not specified or value is not specified, then dont bother doing anything but regular show
if { 0 == [getopt argv -radix radix] } {
return [eval show $args]
}
if { 0 == [getopt argv -value] } {
return [eval show $args]
}
# If radix isnt enum, just pass off to regular show
if { 0 == [string equal -nocase $radix "enum"] } {
return [eval show $args]
}
# Now get the signal, its value and its type
set var [lindex [eval show $argv] 0]
set val [lindex [show $var -value] 1]
set typ [lindex [show $var -type] 1]
# If the type isnt an enum, error
if { 0 == [string equal -nocase [lindex $typ 0] "ENUM"] } {
return "The type of variable $var is not an enumerated type"
}
# Process the enumerations
set enuml [lindex $typ 2]
# Find the value name
foreach v $enuml {
if { $val == [lindex $v 1] } {
set enumname [lindex $v 0]
break
}
}
# If could not be found....
if { 0 == [info exists enumname] } {
return "The variabel $var has a value which does not map"
}
# Get rid of radix from args
getopt args -radix trashcan
# Replace all values with the name
set retval [eval show $args]
set retshow $retval
foreach v [lsearch -all $retval $val] {
set retshow [lreplace $retshow $v $v $enumname]
}
return $retshow
}
因此,如果我输入任何其他非基数枚举eshow命令,它将传递给show,但否则,它将用其名称替换所有值并返回与替换时显示相同的事物 . 正如我所说,我真的想要一个更好的解决方案,但如果有人想要使用我的功能,这里就是 .