How to verify that Verumog enum is valid?

If I get the listing:

my_cmd cmd = my_cmd'(value_from_bus); 

How easy is it to verify that cmd is a valid cmd?

 typedef enum int { ADD = 1, SUBTRACT = 3, MULTIPLY = 7 } my_cmd; 
+5
source share
2 answers

You can also use $cast to check if this is true and copy at the same time. Therefore, instead of executing: cmd = my_cmd'(value_from_bus); You can do it:

 if ($cast(cmd, value_from_bus)) $display("Valid: %s", cmd.name()); else $display("Invalid"); 

Example Playground EDA

+9
source

You can use the enum name () function:

  if (cmd.name() == "") $display("%0d is bad", cmd); else $display("%s:%0d is good", cmd.name(), cmd); 

EDA Playground Example

+3
source

Source: https://habr.com/ru/post/1210619/


All Articles