In verification activity, many of us came across a situation where we need to regenerate bugs with specific scenario or to achieve coverage, we need to create scenario with specific value. In this case, generalized sequences are very useful which takes command line arguments as input and generate those scenarios. So we don't need to modify the existing code or don't require to code new scenarios.
Data types like int or string can be easily passed through command line argument and the value is get into the code using "$value$plusargs" system verilog function.
Now, consider a case where a scenario required with specific enum value. System verilog doesn't support for providing enum name through command line argument directly. So in that case, either string shall be passed through command line and it shall be converted into enum in the code or enum type shall be passed through command line and it shall be cast to enum type.
In UVM 1.2, a feature is added for passing enum through command line and let's explore this feature with detail example:
In the below example, an enum "data_type_e" is declared and to get its value through command line argument, it is defined with "uvm_enum_wrapper" as this class contains method "from_name" through which any argument passed as a string through command line, can be converted into the defined enum. Here, any enum values can be passed through command line argument as a string and in the code it gets as a string using "$value$plusargs" and the string is passed through "from_name" function to get its correct enum value and it can be used in the code. If enum value is not defined then this function returns 0.
Example:
typedef enum {DT_1, DT_2, DT_3, DT_4} data_type_e;
typedef uvm_enum_wrapper#(data_type_e) uvm_dt;
data_type_e dt;
string str;
initial begin
void'($value$plusargs("DATA_TYPE=%0s", str));
if(!(uvm_dt::from_name(str, dt)))
$display("Wrong Data Type Provided.");
else
$display("Data Type=%0s",dt.name());
While simulating above code with command line argument "+DATA_TYPE=DT_4", it receives DT_4 enum value. Here, DT_5 is passed which is not a part of enum values then "from_name" will return 0.
Command with Questa Tool:
vsim "+DATA_TYPE=DT_4" -c -do "run -all; q" -f questa.tops
Output:
Data Type=DT_4
Data types like int or string can be easily passed through command line argument and the value is get into the code using "$value$plusargs" system verilog function.
Now, consider a case where a scenario required with specific enum value. System verilog doesn't support for providing enum name through command line argument directly. So in that case, either string shall be passed through command line and it shall be converted into enum in the code or enum type shall be passed through command line and it shall be cast to enum type.
In UVM 1.2, a feature is added for passing enum through command line and let's explore this feature with detail example:
In the below example, an enum "data_type_e" is declared and to get its value through command line argument, it is defined with "uvm_enum_wrapper" as this class contains method "from_name" through which any argument passed as a string through command line, can be converted into the defined enum. Here, any enum values can be passed through command line argument as a string and in the code it gets as a string using "$value$plusargs" and the string is passed through "from_name" function to get its correct enum value and it can be used in the code. If enum value is not defined then this function returns 0.
Example:
typedef enum {DT_1, DT_2, DT_3, DT_4} data_type_e;
typedef uvm_enum_wrapper#(data_type_e) uvm_dt;
data_type_e dt;
string str;
initial begin
void'($value$plusargs("DATA_TYPE=%0s", str));
if(!(uvm_dt::from_name(str, dt)))
$display("Wrong Data Type Provided.");
else
$display("Data Type=%0s",dt.name());
While simulating above code with command line argument "+DATA_TYPE=DT_4", it receives DT_4 enum value. Here, DT_5 is passed which is not a part of enum values then "from_name" will return 0.
Command with Questa Tool:
vsim "+DATA_TYPE=DT_4" -c -do "run -all; q" -f questa.tops
Output:
Data Type=DT_4