Any way to pass enum values by name as commandline args?
<p>Is there any way to pass the value of an enum by name from the commandline? Rather what's the cleanest solution?</p>

<p>I tried the below,</p>

<pre><code>typedef enum int unsigned { white, black, red } colour_e;
class house;

  rand colour_e colour;

  string n_colour = "white";

  constraint c_colour {
    colour.name() == n_colour;
  }

endclass: house

program top;

  house paradise;

  initial begin
    paradise = new();
    void'($value$plusargs("colour=%0s", paradise.n_colour));
    if (!paradise.randomize())
      $display("not randomized");
    else   
      $display("paradise.colour = %s",paradise.colour);
  end

endprogram: top
</code></pre>

<p>I would want to pass something like this <code>+colour=black</code>. so that the paradise.colour is assigned black.</p>

<p>vcs cribbed for using <code>enum.name()</code> in the constraints.</p>

<p>below is the error.</p>

<blockquote>
  <p>Error-[NYI-CSTR-SYS-FTC] NYI constraint: sys function calls
  T-enum_1.sv, 9 $unit, "this.colour.name"   System function calls are
  not yet implemented in constraints.   Remove the function call or if
  possible replace it with an integral state   variable assigned in
  pre_randomize().</p>
</blockquote>

<p>while Riviera cried as below</p>

<blockquote>
  <p>ERROR VCP7734 "Type of 'this.colour.name()' is not allowed in a
  constraint block. Only integral types are allowed in a constraint
  block." "design.sv" 9  1 ERROR VCP7734 "Type of 'n_colour' is not
  allowed in a constraint block. Only integral types are allowed in a
  constraint block." "design.sv" 9  1 WARNING VCP7114 "STRING value
  expected for format specifier %s as parameter
  paradise.colour." "testbench.sv" 13  54</p>
</blockquote>

<p>which brings the question to me, does everything in the contraint block has to be of integral type (just like we cannot declare a <code>string</code> as <code>rand</code> variable)? </p>

<p>ANyone wants to play around the code please have a look at the code at EDA playground <a href="http://www.edaplayground.com/x/Cn6" rel="nofollow">here</a></p>