title: Casting enum to logic
body: <p>Consider the following module declaration:</p>
  
  <pre><code>module DFF(d, q, CLK, RESET);
   parameter W = 2;
   input  [W-1:0] d;                      
   input  CLK;                                
   input  RESET;      
   output logic [W-1:0]   q; 
  
  //....
  endmodule
  </code></pre>
  
  <p>What is the proper way of instantiating it where d and q are of enum type? Here is my enum type:</p>
  
  <pre><code>typedef enum logic [1:0] {ENUM_IDLE = 0,
              ENUM_S1 ,
              ENUM_S2
              } T_STATE;
  </code></pre>
  
  <p>I would like to instantiate the DFF for a T_STATE variable type:</p>
  
  <pre><code>T_STATE d, q;
  DFF dff_inst (.d(d), .q(q), .CLK(CLK), .RESET(RESET));
  </code></pre>
  
  <p>This generates compile/enumeration error. I have also unsuccessfully tried:</p>
  
  <pre><code>DFF dff_inst (.d(logic'(d)), .q(logic'(q)), .CLK(CLK), .RESET(RESET));
  </code></pre>
  
  <p>and</p>
  
  <pre><code>DFF dff_inst (.d(logic[1:0]'(d)), .q(logic[1:0]'(q)), .CLK(CLK), .RESET(RESET));
  </code></pre>
  
  <p>I would like to keep the DFF definition as is, but cast the enum type to logic.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>This one, suggested in <a href="http://standards.ieee.org/getieee/1800/download/1800-2012.pdf" rel="nofollow">IEEE Std 1800-2012</a>, 6.24.1, also generates an elaboration error:</p>
  
  <pre><code>typedef logic [$bits(T_STATE) - 1 : 0] T_STATE_LOGIC; 
  DFF dff_inst (.d(T_STATE_LOGIC'(d)), .q(T_STATE_LOGIC'(q)), .CLK(CLK), .RESET(RESET));
  </code></pre>