Viewing enum names in vcs ucli

2.9k views Asked by At

I am working in VCS UCLI (ie, the command line interface) and am having trouble getting VCS to display various state variables, of a typedef'd enum type, value as the name rather than the number. For example, I have some SystemVerilog like this:

typedef enum logic [1:0] {A, B, C} state_t;

state_t s;
...

Now in ucli, I want to see the value of s (say its in state A) so I type something like:

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} } }

(Or something like that). I have read the ucli user guide, and it seems like symbolic radix, the only one I know of that might possibly be close, just uses the raw value from the enum, not the enum name. I have tried calling the .name() method for variable s using the call command in ucli (ucli% call {$display("%s", s.name())}), but it doesnt seem to be supported. I know VCS has the capacity to print the enum name, it certainly can in DVE, but I am having trouble coming up with ways to get to show me in the ucli.

Does anyone know how to get the ucli to print the enum name instead of the number when queried? Is enum-type radix somehow (user-defined like in DVE?), use some SystemVerilog system call to get the name, anything like that?

(Note, I understand I could just use the DVE, but I am trying to use the ucli to simply the interface for potential users, this is for educational purposes and I want to mask alot of the ucli interface (and VCS interface in general) to not overwhelm students and get some variables easily; Im turning the vcs ucli into a simple processor simulator)

++++++++++++ UPDATE ++++++++++++

I came up with a very hacky solution but I would really like a better approach. I quickly wrote my own wrapper for show (called eshow) whish ill replace any -value with the enum name if -radix enum is set:

#
# 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
}

Thus, if I type any other non-radix enum eshow commands, it will pass to show, but otherwise, it will replace all values with thier names and return the same thing show would with the replacement. As I said, I REALLY want a better solution, but in case anyone wants to use my function, here it is.

0

There are 0 answers